Monday, June 13, 2011

Query to find nth highest salary in SQL Server

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 to Pinal Dave!!!

No comments:

Post a Comment