Why does a LEFT JOIN stop preserving unmatched rows after I add a filter?
Quick answer
A LEFT JOIN preserves left-side rows that have no matching right-side row under its join condition. But if you put a right-table condition in WHERE, unmatched rows have NULL on the right and may be removed because the condition is not true. Put the condition in ON when it should limit which right-side rows match while keeping every left-side row.
The question, the details, the next step.
A practical checklist
Identify which left-side rows must remain even without a match.
Decide whether the condition limits matches or filters final rows.
Put right-table match criteria in ON when unmatched left rows must be preserved.
Test a row with no match and one with only a nonqualifying match.
Confirm the behavior against your database's documentation.
A few more useful answers
Does putting a condition in ON mean it is ignored?
No. It determines which right-side rows qualify as matches. If none qualify, the LEFT JOIN can still return the left-side row with NULL right-side columns.
Can I use WHERE for conditions on the left table?
Yes, if you intend to filter left-side rows too. A WHERE condition on the left table can remove those rows regardless of whether the join is outer.
What if I want only customers with an open order?
Use a result filter that requires an open order, such as the WHERE form shown above. That intentionally excludes customers without a qualifying open order.
Sources
References used for this guide.
- [S1] SQLite SELECT: outer-join and WHERE processing sqlite.org · Checked
