INNER JOIN vs LEFT JOIN: what's the difference?
INNER JOIN returns only the rows that have a match in both tables. LEFT JOIN returns every row from the left table, and fills the columns from the right table with NULL where there is no match. Use LEFT JOIN when you must not lose rows, for example customers who haven't ordered yet.
Quick comparison
| INNER JOIN | LEFT JOIN | |
|---|---|---|
| Rows from the left table without a match | Dropped | Kept, with NULLs |
| Typical use | Orders with their product details | All customers, with their orders if they have any |
| Find rows without a match | Not possible | WHERE right_table.id IS NULL |
What do the two queries return?
Three customers: Ana, Ben and Cara. Only Ana and Ben have orders.
SELECT c.name, o.idFROM customers cINNER JOIN orders o ON o.customer_id = c.id;
Returns Ana's and Ben's orders. Cara disappears.
SELECT c.name, o.idFROM customers cLEFT JOIN orders o ON o.customer_id = c.id;
Returns the same rows plus one row for Cara, with NULL as the order id.
How do you find customers who never ordered?
This is one of the most common SQL interview questions:
SELECT c.nameFROM customers cLEFT JOIN orders o ON o.customer_id = c.idWHERE o.id IS NULL;
Why does my LEFT JOIN behave like an INNER JOIN?
Because a filter on the right table in WHERE removes the NULL rows again. This query loses every customer without a 2026 order:
… LEFT JOIN orders o ON o.customer_id = c.idWHERE o.order_date >= '2026-01-01';
Move the condition into ON to keep all customers:
… LEFT JOIN orders o ON o.customer_id = c.id AND o.order_date >= '2026-01-01';
Why are my totals too high after a join?
If the key on the right side is not unique, every left row is repeated once per match. Summing a column from the left table after such a join counts it several times. Check with SELECT key, COUNT(*) … GROUP BY key HAVING COUNT(*) > 1 before you join, or aggregate the right table first.
A related trap: after a LEFT JOIN, COUNT(*) counts Cara as 1, while COUNT(o.id) correctly counts her 0 orders.
Practise JOIN Practise LEFT JOIN