Search this blog

Monday, June 1, 2009

Find Nth Highest Salary

Following Query Template Helps to find Nth Highest Salary,

SELECT TOP 1
FROM
(
SELECT DISTINCT TOP
FROM<Table Name>
ORDER BY DESC
) a

ORDER BY

Sample Query to find 5th Highest Salary from Employee Table:

SELECT TOP 1 salary
FROM
(
SELECT DISTINCT TOP 5 salary
FROM Employee
ORDER BY salary DESC
) a

ORDER BY salary

No comments:

Post a Comment