Loading

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.

JoinUse it whenReal example
INNER JOINyou want only the rows that match on both sidesorders with their customers' names: an order with no customer, or a customer with no order, is left out
LEFT JOINyou want every row of the left table, matched or notevery customer with their orders; adding WHERE orders.id IS NULL lists the customers who never ordered
RIGHT JOINyou 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 insteadevery product with its sales, written as products LEFT JOIN sales
FULL OUTER JOINyou need the unmatched rows of both sidesmatching 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 JOINyou need every combination of the two tablesevery shirt size with every colour, to list the variants of a product
SELF JOINa table refers to its own rowseach 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.

All the tables