SQL Server Performance Forum – Threads Archive
Criteria on INNER JOIN vs. WHERE
Hi,What is most efficient: SELECT *
FROM Company a
INNER JOIN Store s
ON a.companyID = s.companyID
INNER JOIN Department d
ON s.storeID = d.storeID
WHERE d.type = ‘A’ or this one: SELECT *
FROM Company a
INNER JOIN Store s
ON a.companyID = s.companyID
INNER JOIN Department d
ON s.storeID = d.storeID
AND d.type = ‘A’ /Mats
No different. It is just a matter of convention. Personally, i would put the condition in WHERE rather than in ON condition.
KH
With INNER JOINs it doesnt matter. But with outer joins its a different story. I’d recommend putting the join condition on the ON clause and the filter condition on the where clause. Roji. P. Thomas
SQL Server MVP
http://toponewithties.blogspot.com
quote:Originally posted by Roji. P. Thomas
With INNER JOINs it doesnt matter. But with outer joins its a different story. I’d recommend putting the join condition on the ON clause and the filter condition on the where clause.
Thanks for your response. Is your recommendation valid for OUTER JOINs also? Is it better to have the filter condition on the WHERE clause than having it on the ON clause? Thanks, Mats
For outer joins, you get different results if you move the conditions from WHERE to ON.
Roji. P. Thomas
SQL Server MVP
http://toponewithties.blogspot.com
Btw, not only this, but when you’re running comp level 9.0 you’ll get a:<br /><pre id="code"><font face="courier" size="2" id="code"><br />USE Northwind<br />SELECT *<br /> FROM db



Frank, we are NOT talking about using the old style Join syntax! Roji. P. Thomas
SQL Server MVP
http://toponewithties.blogspot.com
I know. [<img src=’/community/emoticons/emotion-5.gif’ alt=’


]]>