Part 67: SELF JOIN: Querying Hierarchical & Tree Data

Part 67 Technology Updated September 12, 2026

Part 67: SELF JOIN: Querying Hierarchical & Tree Data

A SELF JOIN is a regular join in which a table is joined with itself.


1. Employee and Manager Hierarchy

In an employees table where manager_id points to another employee's id:

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

Key Takeaways

  • Use separate table aliases (e and m) to join a table with itself.

In Part 68, we will master Multi-Table Joins: Joining 3 or More Tables Efficiently!