To get the names of the employees with the 2nd highest distinct salary amount you can use.
;WITH T AS ( SELECT *, DENSE_RANK() OVER (ORDER BY Salary Desc) AS Rnk FROM Employees ) SELECT Name FROM T WHERE Rnk=2;
If Salary is indexed the following may well be more efficient though especially if there are many employees.
SELECT Name FROM Employees WHERE Salary = (SELECT MIN(Salary) FROM (SELECT DISTINCT TOP (2) Salary FROM Employees ORDER BY Salary DESC) T);
For more information about Test Script:http://stackoverflow.com/questions/7417415/how-to-get-second-highest-salary-employees-in-a-table
How we can get nth max salary from Employee Table (EMP_ID, Salary)
Emp_id salary 1 1000 3 2000 4 16000 2 10000 7 19000 8 12000
e.g. for 3rd max salary, salary is 12000 so answer will be emp_id : 8