Junior
JOINs
SQL & Databases
When do you use a self-join in SQL Server?
Short answer: When rows relate to other rows in the same table — classic employee/manager, find peers in same department, or compare a row to another version.
Sample solution
T-SQL
SELECT e.Name AS Employee, m.Name AS Manager FROM Employees e LEFT JOIN Employees m ON e.ManagerId = m.EmpId;
Always alias both sides clearly (e/m) — interviewers flag missing aliases.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png