I will try to explain in my own way:
Consider the tables below.
tblQuestions
QuestionId 1 2 QuestionTitle Your Name? Your Age?
tblPersons
PersonId 1 2 PersonName Person1 Person2
tblAnswers
AnswerId 1 PersonId 1 QuestionId 1 Answer My Name is Person1
Try this query with WHERE , it will return only one result.
SELECT q.QuestionId, q.QuestionName, a.Answer FROM tblQuestions q LEFT OUTER JOIN tblAnswers a ON q.QuestionId = a.QuestionId WHERE a.PersonId = 2 OR a.PersonId IS null
Now try this query with ON , it will return two .
SELECT q.QuestionId, q.QuestionName, a.Answer FROM tblQuestions q LEFT OUTER JOIN tblAnswers a ON q.QuestionId = a.QuestionId AND (a.PersonId = 2 OR a.PersonId IS null)
The difference in the results is that the filter PersonId = 1 OR PersonId Is NULL , when this filter is applied through the WHERE result, is ONE record, when it is applied to `ON ', the result is TWO records.
source share