Section: joins

Self join a table

sql
sql
SELECT e.id, e.full_name, m.full_name AS manager_name
FROM employees e
LEFT JOIN employees m ON m.id = e.manager_id;
Explanation

Self joins are common in hierarchical data such as org charts.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing joins
Inner join two tables
Return rows where both tables match.
OpenIn sheetsqlsame section
Left join to keep unmatched parent rows
Return all rows from the left table and matching rows from the right table.
OpenIn sheetsqlsame section
Join and aggregate child rows
Count child rows per parent.
OpenIn sheetsqlsame section
Filter with a subquery
Return users who have at least one paid order.
Use EXISTS for correlated filtering
Return users who have orders.
Use a CTE to isolate recent orders
Create a readable query pipeline with `WITH`.