Does it matter whether a condition goes in ON or WHERE, and why does a WHERE filter break a LEFT JOIN?
Short answer
With INNER JOIN, a condition in ON or WHERE gives the same result. With LEFT JOIN it's completely different: WHERE runs after the join and drops rows whose right side is NULL.
| Join + where the right-table condition goes | Unmatched left row |
|---|---|
INNER JOIN, in ON or WHERE |
Dropped (same either way) |
LEFT JOIN, in ON |
Kept, right columns = NULL |
LEFT JOIN, in WHERE |
Dropped: becomes an INNER JOIN |
3 points to say:
- INNER:
ONorWHEREis the same. - LEFT: filtering the right table in
WHEREmakes it inner. - Right table →
ON, left table →WHERE.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.