Self Joins
A self join joins a table to itself. You use aliases to treat the same table as two separate tables.
This is useful for hierarchical data like employee/manager relationships:
Key points:
- You MUST use aliases to distinguish the two copies
LEFT JOINensures employees without a match still appear- Common for org charts, referral chains, and category trees
Self joins are a powerful pattern once you understand them.
Check your understanding
What is a self join?
Examples run on the employees sample database. Open any of them in the playground to experiment.