Self Join

SQL SELF JOIN

A table can be joined to itself in a self-join.

SQL Self Join syntax

SELECT column_name(s)
FROM A_table, B_table
WHERE A_table.column_name = B_table.column_name;

Test

IDNAMEPARENT_ID
1aaaNULL
2bbbNULL
3ccc1
4ddd1
5eee2
6fffNULL
7ggg6

Example

SELECT b.*
FROM Test a, Test b 
WHERE a.id = b.parent_id
ORDER BY a.id ;

Results

IDNAMEPARENT_ID
3ccc1
4ddd1
5eee2
7ggg6