Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

    SQL... umm, technique....

    Can I rewrite this:

    Code:
    SELECT DISTINCT [Broch Section]
    FROM [myProducts]
    WHERE [Product Type]='Accommodation'
    AND [Product ID] IN (
      SELECT SKUNum FROM tblACC_Live
      INNER JOIN tblTRV_Live on tblACC_Live.TRVID=tblTRV_Live.TRVID
      WHERE tblTRV_Live.DepartDate='23/05/2004'
    )
    ORDER BY [Broch Section]
    as this:
    Code:
    SELECT DISTINCT [Broch Section]
    FROM [myProducts]
    INNER JOIN tblACC_Live ON myProducts.[Product ID]=tblACC_Live.SKUNum
    INNER JOIN tblTRV_Live on tblACC_Live.TRVID=tblTRV_Live.TRVID
    WHERE [myProducts].[Product Type]='Accommodation'
    AND tblTRV_Live.DepartDate='23/05/2004'
    ORDER BY [Broch Section]
    And more importantly, what's the difference between the two? Will they get different results? Is one faster? Is one faster in one way but not in another? Is it all a little pointless?

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SQL... umm, technique....

    Originally posted by Spudhead

    And more importantly, what's the difference between the two? Will they get different results? Is one faster? Is one faster in one way but not in another? Is it all a little pointless?
    check this thread:
    JOIN OR SubQuery?
    just the beginning of an answer

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If that's MSSQL use the Query Analyzer program to run both forms of the query so you can compare the results and also use the tools it provides to see exactly what steps are used in each form so you know for sure which one takes more work.
    Check out the Forum Search. It's the short path to getting great results from this forum.


  •  

    Posting Permissions

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