www.webdeveloper.com
Results 1 to 2 of 2

Thread: Join table question

  1. #1
    Join Date
    May 2010
    Posts
    140

    Join table question

    Sometimes JOINS can be confusing. What's the difference with the two queries below? Why it will bring different results?

    Code:
    SELECT PK1.PNN,PK1.NAME,PK2.GBT,SSM,RSM
    				 FROM PK1
    				 left join PK2 ON PK2.PNN = PK1.PNN AND PK2.MANT = PK1.MANT";
    				left join MSS ON dbo.MSS.RSM = PK2.GBT AND dbo.MSS.MANT = PK2.MANT
    				
    				SELECT PK1.PNN,PK1.NAME,PK2.GBT,SSM,RSM  
    				FROM MSS 
    				left join PK2 ON PK2.GBT = MSS.RSM AND MSS.MANT = PK2.MANT 
    				left join PK1 ON PK1.PNN = PK2.PNN AND PK1.MANT = PK2.MANT

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Because you are using left joins, each query will return every row of the "from" table regardless of the existence of any matches in the left-joined tables (returning null for any such fields where there are no joins). Since the "from" table is different in each query, you would get different results (unless there is at least one join-able row in each table for each row in the other tables).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles