A SELF JOIN occurs when a table is joined to itself using different aliases so that rows within the same table can be compared or related.
Self joins are useful when hierarchical or relationship information is stored within one table.
Find each employee together with their manager from the same Employees table.
SELECT
e.EmployeeName AS Employee,
m.EmployeeName AS Manager
FROM Employees e
LEFT JOIN Employees m
ON e.ManagerID = m.EmployeeID;
Used for employee hierarchies, organizational structures, category relationships, and parent-child data.
- A table can be joined to itself.
- Different aliases distinguish the table instances.
- Self JOINs are common with hierarchical data.
- The join condition defines the relationship between rows.
- Manager-employee relationships are a common example.
What is a SELF JOIN?
A SELF JOIN joins a table to itself using different aliases.
Where is SELF JOIN commonly used?
It is commonly used for hierarchical relationships such as employee-manager structures.