The Where-used atlas
SQL joins, and where each is used
A join puts rows of two tables side by side wherever a condition matches. Each kind decides what happens to the rows that find no partner.
| Join | Use it when | Real example |
|---|---|---|
| INNER JOIN | you want only the rows that match on both sides | orders with their customers' names: an order with no customer, or a customer with no order, is left out |
| LEFT JOIN | you want every row of the left table, matched or not | every customer with their orders; adding WHERE orders.id IS NULL lists the customers who never ordered |
| RIGHT JOIN | you want every row of the right table; it is the mirror of LEFT JOIN, so most people swap the two tables and write LEFT JOIN instead | every product with its sales, written as products LEFT JOIN sales |
| FULL OUTER JOIN | you need the unmatched rows of both sides | matching a bank statement against a shop's own ledger, to see the payments each side is missing; MySQL has no FULL JOIN, so there it is a LEFT JOIN and a RIGHT JOIN joined by UNION |
| CROSS JOIN | you need every combination of the two tables | every shirt size with every colour, to list the variants of a product |
| SELF JOIN | a table refers to its own rows | each employee with their manager, both from one staff table, joined to itself under two names |
Checked 2026-10-26 against: The PostgreSQL documentation; The MySQL reference manual.