T-sql is the most preferred connection method
I have 2 sql query below. What is the most preferred method of getting table1.date> 0
Option1:
select table1.id,table2.firstname, table2.lastname
from table1 join table2 on table1.id = table2.id and table1.date > 0
Option2:
select table1.id,table2.firstname, table2.lastname
from table1 join table2 on table1.id = table2.id where table1.date > 0
source to share
ALWAYS use the second option.
For INNER JOIN
they are equivalent.
The OUTER JOIN
two versions will return different result sets!
If you put this filter in the criteria ON
for OUTER JOIN
, you will have filtered records before applying JOIN
(and not after), which can give unexpected results.
source to share
Not a question, but an outer join, but as opposed to where the situation can be changed.
Consider the following. The second returns all the lines in docSVsys, while the first does not. Where the outer join was mostly included in the regular join.
select COUNT(docSVsys.sID)
from docSVsys
left outer join docMVtext
on docMVtext.sID = docSVsys.sID
where docMVtext.fieldID = 130
select COUNT(docSVsys.sID)
from docSVsys
left outer join docMVtext
on docMVtext.sID = docSVsys.sID
and docMVtext.fieldID = 130
I had some big requests that pulled a condition from where it was and resulted in the same request but a different plan.
source to share