Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Where and Join On Clause the Same? Expand / Collapse
Author
Message
Posted Saturday, May 2, 2009 1:40 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Monday, November 17, 2014 1:47 PM
Points: 554, Visits: 1,206
Comments posted to this topic are about the item Where and Join On Clause the Same?
Post #708968
Posted Monday, May 4, 2009 6:54 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 8:47 AM
Points: 20,801, Visits: 32,730
Excellent question. This is one of the things you have to watch for when converting a query that uses the old style outer joins to the ANSI standard outer joins. What may seem to be a filter condition in the where clause may aslo need to be moved to the FROM clause as part of the join criteria.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #709351
Posted Monday, May 4, 2009 8:51 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, March 31, 2011 1:40 AM
Points: 1,938, Visits: 208
Good question. I had to debug an issue just like this last week with one of the developers. We decided we liked the old style syntax better!
Post #709426
Posted Monday, May 4, 2009 10:01 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, December 20, 2012 1:03 PM
Points: 265, Visits: 589
An explanation of why the order of evaluation, "from" followed by "where" has this effect is in order here. Merely stating that the order of evaluation as the reason misses an important lesson.
Post #709478
Posted Monday, May 4, 2009 10:50 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 8:47 AM
Points: 20,801, Visits: 32,730
dunnjoe (5/4/2009)
Good question. I had to debug an issue just like this last week with one of the developers. We decided we liked the old style syntax better!


I prefer the ANSI style better. It separates the join criteria from filter criteria.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #709511
Posted Tuesday, May 5, 2009 8:43 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, May 8, 2009 1:23 AM
Points: 34, Visits: 20
Good question but not well presented. Try it on a database which is case sensitive and you get "none of the above"! Case is always important and as they say at the FBI Academy "To assume makes ..." (courtesy of the Silence of the Lambs)
Post #710301
Posted Thursday, May 7, 2009 11:46 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 4:07 PM
Points: 1,359, Visits: 1,727
Here's how I see the difference. It may help you to understand the order of execution, or it may just confuse you, but it's how I read the statements semantically. Your results may vary.
SELECT * 
FROM T1
LEFT JOIN T2
ON t1.col1 = t2.col1
WHERE t2.col1 IS NULL

is telling the server to filter the result set to those rows with a NULL value in the column output from t2.col1, whereas
SELECT * 
FROM T1
LEFT JOIN T2
ON t1.col1 = t2.col1
AND t2.col1 IS NULL

is telling the server to condition the join on there being a NULL value in t2.col1 (i.e, to filter the input from t2 into the join to rows with a NULL in t2.col1)
Post #712290
Posted Friday, May 15, 2009 3:10 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, August 22, 2011 5:41 AM
Points: 92, Visits: 17
Question is superb. Its simple but gives major difference.
For the first statement, It joins and evaluates the where condition. But for second it evaluates the condition while applying joins .Thats the difference.

Post #717716
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse