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.

orders order_id customer_id ← status JOIN customers → customer_id first_name city row
A JOIN stitches tables together using a shared key (here: customer_id).

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

  1. ON decides which right rows are allowed to match.
  2. WHERE decides which result rows survive after the join.
  3. 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.

Practice JOIN + filter

Related guides