Go Back   Rhinocerus > Newsgroup > Newsgroup comp.databases.* > Newsgroup comp.databases.ms-sqlserver

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2011, 05:30 PM
Phil Hunt
Guest
 
Posts: n/a
Default How does it do it

In the studio query design, I can join any tables up. Now I understand Inner
Join is associative. But if there is an Outer join in the mix, how does the
studio determine the order of the joint ?


Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 10-03-2011, 09:34 PM
Erland Sommarskog
Guest
 
Posts: n/a
Default Re: How does it do it

Phil Hunt (aaa@aaa.com) writes:
> In the studio query design, I can join any tables up. Now I understand
> Inner Join is associative. But if there is an Outer join in the mix, how
> does the studio determine the order of the joint ?


I don't know. And the reason I don't know is because I never use the
Query Designer. And I can't really recommend usage of it. There are
just too many SQL constructs it does not support.

On the other hand, I do know the difference between LEFT and RIGHT JOIN.
Well, tney are not very different. These two queries are equal:

SELECT a.col1, b.col2
FROM a
LEFT JOIN b ON a.col0 = b.col0

SELECT a.col1, b.col2
FROM b
RIGHT JOIN a ON a.col0 = b.col0

Both queries will return all rows in table a. For the rows where there is no
matching row in b, the value of b.col2 will be NULL.

So when do you use LEFT JOIN and when do you use RIGHT JOIN? The answer
is that you always use LEFT JOIN and never RIGHT JOIN. At least that is
what I do. RIGHT JOIN gives me headache, because everything is
backwards.

The simple rule is: in a LFFT JOIN all rows in the table on the left side
are retained, while the table on the right side is filtered by the ON
clause.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 04:12 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.