Skip to main content
SQL • LESSON 85

SELF JOIN

How can we find each employee together with their manager?

Advanced3 Minutes980 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