Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    149

    Unanswered: Query Performance

    Hello all-

    I have a general question. I realize that joins are most of the time better than subqueries. Now that we have the derived tables, if I put the subquery as a derived table and join it with the other tables, will it make any difference in the performance?

    eg:

    SELECT EmpId
    FROM Emp
    WHERE EmpSalary = (SELECT MAX(EmpSalary)
    FROM Emp Emp2)

    Vs

    SELECT Emp1.EmpId
    FROM Emp Emp1
    INNER JOIN (SELECT MAX(EmpSalary) FROM Emp) Emp2
    ON Emp1.EmpSalary = Emp2.EmpSalary

    (I know that there are better ways of writing this query, sorting my empsalary and getting the top 1 etc. This is just an example to demostrate my question.)

    Appreciate your time
    Thnx

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Did you do a show plan on the 2?

    That will show you...but I don't think you'll see a difference...

    It depeneds more on the number of rows you have and the indexing...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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