I was wondering about the difference :
select *
from Table1 T1
left join Table1 T2 on T1.id = T2.id + 1 and (T2.id > 3)
vs
select *
from Table1 T1
left join Table1 T2 on T1.id = T2.id + 1
where (T2.id > 3)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a significant difference.
The where clause is changing the left join to an inner join, since it is not allowing for the null value to be returned from the left join. This means all the rows where the left join doesnt find a matching record would be excluded, since the null value returned is compared to 3 and it discards the row (this is the same effect as making it an inner join)
The first statement is applying the filter within the join:
This means it will take effect and filter the rows that can be joined to using the left join, but this will not cause rows to be discarded when the left join fails to find a matching row.