thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Intermediate

Self Join

A join of a table to itself, using two aliases, to compare rows within the same table.

Definition

Self joins handle hierarchical or comparative data, such as employees and their managers stored in the same table, or finding pairs of rows that share attributes.

Example

SELECT e.Name AS Employee, m.Name AS Manager FROM Employees e LEFT JOIN Employees m ON e.ManagerID = m.EmpID;

Exam tip

A self join requires table aliases. Use a LEFT self join so the top-level manager, whose ManagerID is NULL, is kept.

Related terms