Skip to main content
SQL โ€ข LESSON 85

SELF JOIN

How can we find each employee together with their manager?

Advancedโฑ 3 Minutesโญ 980 XP
๐Ÿค” THE QUESTION

How can we find each employee together with their manager?

๐Ÿ’ก WHAT IS IT?

A SELF JOIN connects a table to itself using distinct aliases (e, m) to resolve hierarchical relationships.

๐ŸŽฏ WHAT IS IT USED FOR?

Manager-employee hierarchies, category breadcrumbs, graph node parent lookups.

๐Ÿ’ป EXAMPLE
SELECT
e.name AS employee_name,
m.name AS manager_name
FROM employees e
LEFT JOIN employees m
ON e.manager_id = m.employee_id;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for SELF JOIN.

  • โœ“ SELF JOIN
  • โœ“ Hierarchy modeling
  • โœ“ Table aliases (e, m)
  • โœ“ Manager-employee mapping