A table joined to itself
Lesson 16 of 24 · SQL.Micro
Some tables point to themselves: each staff member has a manager who is also staff. Join the table twice with two aliases.
FROM staff e JOIN staff m ON e.manager_id = m.id
The aliases make the two roles clear: e for employee, m for manager.
The CEO has no manager, so an inner join leaves the CEO out.
Check yourself
Why are two aliases required in a self join?
To tell the two copies of the table apart
Show each staff member's name next to their manager's name (only people who have a manager).
Do it in the browser: a real SQL tool, a short mission and instant feedback. No install.
Start this lesson — free