Beginner

632. Employee Manager Self JOIN

Use a Self JOIN to retrieve employee and manager relationships.

📘 Lesson 632 of 728 ⏱ 14 min 🎯 Intermediate

An employee-manager Self JOIN connects an employee row to another row in the same Employees table representing the employee's manager.

Organizational hierarchy reporting is a common requirement in HR and workforce analytics.

Display employee names and their manager names.

SQL
SELECT
    e.EmployeeID,
    e.EmployeeName,
    m.EmployeeName AS ManagerName
FROM Employees e
LEFT JOIN Employees m
    ON e.ManagerID = m.EmployeeID;

Used in HR reports, organizational charts, approval workflows, and management dashboards.

  • Employee and manager can exist in the same table.
  • ManagerID points to another EmployeeID.
  • The table needs two aliases.
  • LEFT JOIN keeps top-level employees.
  • This is a common hierarchical data pattern.
How do you find an employee's manager using SQL?

Use a Self JOIN between the employee's ManagerID and another row's EmployeeID.

Why use LEFT JOIN here?

It keeps employees whose ManagerID is NULL, such as top-level managers.

Have you finished this lesson?

Introduction to SQL – All Lessons