A SELF JOIN is a JOIN where a table is referenced more than once using different aliases.
Many business datasets contain relationships between records stored in the same table.
Display each employee along with their manager's name when both employees and managers are stored in the same Employees table.
SELECT
e.EmployeeName,
m.EmployeeName AS ManagerName
FROM Employees e
LEFT JOIN Employees m
ON e.ManagerID = m.EmployeeID;
SELF JOIN is useful for organizational hierarchies, employee-manager relationships, referrals, parent-child records, and comparisons within the same dataset.
- A SELF JOIN references the same table twice.
- Different aliases identify each table instance.
- It is useful for hierarchical data.
- The table is not physically duplicated.
- Join conditions define the relationship.
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.