Beginner

631. Self JOIN Basics

Learn how a table can be JOINed with itself to compare related rows.

📘 Lesson 631 of 728 ⏱ 13 min 🎯 Intermediate

A Self JOIN is a JOIN where the same table is referenced more than once using different aliases.

Many business datasets contain relationships within the same table, such as employees and their managers.

Show each employee along with their manager.

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

Used in employee hierarchies, category structures, account relationships, and organizational reporting.

  • The same table is referenced twice.
  • Different aliases are required.
  • Aliases identify the different roles of the table.
  • Self JOINs are useful for hierarchical data.
  • LEFT JOIN can preserve employees without managers.
What is a Self JOIN?

A Self JOIN joins a table to itself using different aliases.

Why are aliases important in a Self JOIN?

They distinguish the different references to the same table.

Have you finished this lesson?

Introduction to SQL – All Lessons