SQL LEFT JOIN
A LEFT JOIN keeps every row from the first (left) table. Where the right table has no match, its columns come back as NULL. That makes it the tool for “including those with none”.
Updated December 1, 2026
Syntax
SELECT a.column, b.column
FROM table_a AS a
LEFT JOIN table_b AS b ON b.a_id = a.id;
Count, including zeros
Every customer and their number of orders. Fay has none, but she still appears with 0. Count a column from the right table, not *, so unmatched rows count as 0.
SELECT c.name, COUNT(o.id) AS orders
FROM customers AS c
LEFT JOIN orders AS o ON o.customer_id = c.id
GROUP BY c.id, c.name
ORDER BY orders DESC, c.name;
| name | orders |
|---|---|
| Ava | 3 |
| Ben | 2 |
| Cara | 1 |
| Dev | 1 |
| Eli | 1 |
| Gus | 1 |
| Hana | 1 |
| Fay | 0 |
Find rows with no match
Keep only the rows where the right side is NULL: products nobody has ever ordered.
SELECT p.name, p.stock
FROM products AS p
LEFT JOIN order_items AS i ON i.product_id = p.id
WHERE i.product_id IS NULL;
| name | stock |
|---|---|
| Desk Lamp | 0 |
| Sticky Notes | 0 |
Common mistakes
- Filtering the right table in
WHERE(for exampleWHERE o.quantity > 1) removes the NULL rows and turns it back into an inner join. Put that condition in theONclause instead. - Using
COUNT(*)after a LEFT JOIN, which counts unmatched rows as 1. - Swapping the table order: the table that must keep all its rows goes first.
Practice LEFT JOIN interactively
Write real queries in your browser and get instant feedback in the lesson “LEFT JOIN” (Unit 5). New learners can start free from the first lesson.
Frequently asked questions
What is the difference between LEFT JOIN and LEFT OUTER JOIN?
None. OUTER is optional.
LEFT JOIN vs INNER JOIN?
INNER JOIN drops rows without a match; LEFT JOIN keeps all rows from the left table.