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;
Result on the SQL Café sample data (8 rows)
nameorders
Ava3
Ben2
Cara1
Dev1
Eli1
Gus1
Hana1
Fay0

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;
Result on the Desk & Co. (online store) sample data (2 rows)
namestock
Desk Lamp0
Sticky Notes0

Common mistakes

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.

Related SQL tutorials