If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Different or not? the two left join queries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-15-09, 07:59
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
Different or not? the two left join queries

Hello Everybody,

I am not sure whether the following two queries are the same or not?

Code:
     SELECT 
              a.* 
     FROM  
              a 
    LEFT JOIN b

              ON   a.ID = b.ID
   
    LEFT JOIN  c
             ON  a.ID = c.ID
Code:
     SELECT 
              a.* 
     FROM  
              a 
    LEFT JOIN b

              ON   a.ID = b.ID
   
    LEFT JOIN  c
             ON  b.ID = c.ID
Thanks
Reply With Quote
  #2 (permalink)  
Old 08-15-09, 09:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
they are not the same joins, but the results are the same

here is some test data that you can use to verify that the joins are different --
Code:
   a      b      c
  21     21     21
  22            22
however, since you are returning only the a columns, the results look the same

note also that if we change the test data as follows--
Code:
   a      b      c
  21     21     21
  22            22
                22
                22
then the results will be different

this example once again shows the folly of "dumbing down" your real question

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On