SQL Server Interview Question #67

What is a SELF JOIN?

Joins, Subqueries, CTEs & Set Operators Mid-Level Intermediate

Detailed Explanation

A self join joins a table to itself using different aliases. It is commonly used for hierarchical or same-table relationships, such as employees and managers.

A self join is not a separate SQL JOIN keyword; it is a normal join where both references point to the same table.

Code Example

SELECT e.Name AS Employee,
       m.Name AS Manager
FROM dbo.Employees AS e
LEFT JOIN dbo.Employees AS m
    ON e.ManagerId = m.Id;