Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    130

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •