Why LEFT JOIN + WHERE Acts Like an INNER JOIN
Filtering the right table in WHERE after a LEFT JOIN removes unmatched rows. Put the filter in ON instead — with a clear shop example.
The common trap
SELECT c.first_name, o.order_id, o.status FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.status = 'paid';
Intent: “all customers, and show paid orders if any.”
Actual result: only customers who have a paid order — same shape as an INNER JOIN.
Why? Unmatched customers get NULL for o.status. NULL = 'paid' is never true, so WHERE deletes those rows.
The fix: filter in ON
SELECT c.first_name, o.order_id, o.status FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id AND o.status = 'paid';
Now every customer survives. Paid orders attach when they exist; otherwise order columns stay NULL.
Mental model
ONdecides which right rows are allowed to match.WHEREdecides which result rows survive after the join.- For OUTER joins, a WHERE on the outer side’s columns quietly deletes the “outer” part.
Related: why NULL comparisons fail.
FAQ
Why does my LEFT JOIN return the same rows as an INNER JOIN?
You probably filtered a right-table column in WHERE (for example o.status = 'paid'). Unmatched left rows have NULL there, so WHERE drops them.
Where should I put the filter on a LEFT JOIN?
Put right-table conditions in the ON clause if you still want unmatched left rows. Use WHERE only for filters that should apply to the final result.
Try it yourself
The fastest way to lock this in is a short drill on the same Northstar Market tables.