select max(sal) of employee

  • Hi folks,

    i have two tables Employee and salary. Employee having the columns empid, name and address and salary table having the columns empid and salary. i want optimize query to get the employee details who is having the max salary.

    i can write query as

    select * from employee where empid = (select empid from salary where salary = (select max(salary) from salary))

    but is there any optimum query other than this?

    thanks,

    Ramu

  • SELECT TOP 1 Employee.*

    FROM Employee inner join salary on employee.empid = salary.empid

    Order by Salary DESC

    Test it out and see if it's better or worse than the one that you have.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply