A LEFT JOIN returns every row from the left table, plus the matching rows from the right table; where there is no match, the right-side columns are NULL. A RIGHT JOIN is the mirror image and keeps every row from the right table. The mysql left join is the one you will use far more often, and any RIGHT JOIN can be rewritten as a LEFT JOIN by swapping the table order.
This guide uses the same sample tables as the INNER JOIN article: customers(id, name, city) and orders(id, customer_id, total).
An inner join drops rows without a match. An outer join keeps them from one side (or both, in other databases). Sample data:
Chen has no orders, but he still appears, with NULL in the order columns. OUTER is optional: LEFT JOIN and LEFT OUTER JOIN are the same.
The classic use of LEFT JOIN is the anti-join: find rows in one table with no related row in another. Filter on a right-side column being NULL:
Test a column that is NOT NULL in the right table, usually its primary key, so a genuine NULL value in a data column cannot be confused with "no match".
This keeps every order, including order 13 whose customer is NULL. The same result comes from swapping the tables and using LEFT JOIN:
Most teams standardise on LEFT JOIN so every query reads from the main table outward, which makes multi-join queries easier to follow.
This is the most common outer-join mistake. A filter on the right table placed in WHERE removes the NULL rows and turns the query back into an inner join:
To keep every customer but only join large orders, put the condition in ON:
Now Chen still appears, and Asha shows only her 120.00 order.
To count orders per customer including customers with none, count a right-table column, not *:
COUNT(*) would count the NULL row as 1, so Chen would wrongly show one order. COUNT(o.id) ignores NULL and gives 0. COALESCE replaces a NULL sum with 0.
You can add more tables after a LEFT JOIN. Keep the later joins as LEFT JOINs as well, otherwise an inner join on a column from the optional table removes the customers that had no orders:
Every customer still appears, and customers without orders show NULL for both the order and the product. If you switch the second join to JOIN, those customers vanish, which is the same trap as filtering in WHERE. When a report looks short a few rows, check each join type and each condition on an optional table first.
Also remember that a LEFT JOIN can multiply rows: a customer with three orders appears three times. That is correct for a listing, but aggregate carefully when you add up values from the left table.
None. OUTER is an optional keyword.
The one written before the JOIN keyword in the FROM clause.
Usually a WHERE condition on the right table removes the NULL rows. Move it into the ON clause.
MySQL has no FULL OUTER JOIN; you combine a LEFT JOIN and a RIGHT JOIN with UNION.
LEFT JOIN keeps all left rows and fills unmatched right columns with NULL; RIGHT JOIN does the opposite. Use WHERE right.pk IS NULL to find missing relations, put right-table filters in ON, count with COUNT(right.column), and prefer LEFT JOIN over RIGHT JOIN for readability.