Thursday, December 22, 2011

Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value

SQL SERVER – Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

where n > 1 (n is always greater than one)

Thanks 

Alok Kumar Sharma



1 comment:

  1. But I need a high performance query which won't sort and use top....

    ReplyDelete