Interview Q&A / SQL & DBMS

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between putting a filter in ON versus WHERE in a LEFT JOIN?

SHORT ANSWER

A filter on the right table in ON limits which rows match while still keeping every left row. The same filter in WHERE runs after the join and removes the NULL-extended rows, turning the LEFT JOIN into an INNER JOIN.

Explain it simply

You want all students listed, along with their 2026 fee receipt if they have one. If the "2026 only" rule is part of matching (ON), students without a 2026 receipt still appear, with a blank. If you apply the rule afterwards (WHERE), every student with a blank is thrown out.

Example

Tables: students (Asha, Ravi) and fees with one row, Asha paid in 2026.

sql
-- filter in ON, keeps Ravi
SELECT s.name, f.year
FROM students s
LEFT JOIN fees f ON f.student_id = s.id AND f.year = 2026;
nameyear
Asha2026
RaviNULL
sql
-- filter in WHERE, loses Ravi
SELECT s.name, f.year
FROM students s
LEFT JOIN fees f ON f.student_id = s.id
WHERE f.year = 2026;
nameyear
Asha2026

Ravi's joined row has f.year = NULL, and NULL = 2026 is not true, so WHERE discards it.

For an INNER JOIN the two placements give the same result.

What to say in the interview

"For outer joins, ON decides what matches, WHERE filters the final rows. A WHERE condition on the nullable side defeats the outer join. Conditions on the preserved table are safe in WHERE."

Common mistakes

  • Putting a right-table filter in WHERE and wondering why unmatched rows vanished.

#sql#joins#left-join#where

Related questions

Practise more SQL & DBMS questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open SQL & DBMS quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.