Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is a self-join?

SQL · Basics & Joins

What is a self-join?

Easysql-03
self-joinaliaseshierarchy

Question

What is a self-join?

Solution

A self-join means joining a table to itself.

Example: employees and their managers are stored in the same table.

employees
---------
id
name
manager_id

Query:

SELECT e.name AS employee,
       m.name AS manager
FROM employees e
LEFT JOIN employees m
    ON e.manager_id = m.id;

We use aliases because the same table appears twice.

Common use cases:

  • Employee → manager relationships
  • Hierarchies
  • Finding related records
  • Comparing rows within the same table

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext