SQL SERVER – Query to Retrieve the Nth highest record from database table

You can replace the “Table” table with your table name and “N” with the level of salary to be determined.

Here is query to find Nth Highest Record from Database Table.

Method 1: Using sub query
SELECT *
FROM Table t1
WHERE (N-1) = (SELECT COUNT(DISTINCT(t2.salary))
FROM Table t2
WHERE t2.salary > t1.salary)

Method 2: Using Top
SELECT TOP 1 Salary
FROM (
SELECT DISTINCT TOP N Salary
FROM Table1
ORDER BY Salary DESC
) AS Emp
ORDER BY Salary

Share this:
Share