Ways to Get N th Largest Salary in SQL Server

Approach 1: using DENSE_RANK()
 
Below example is for getting third largest salary.

Consider following details :

Table: Emp

Column: name, Salary

(SELECT name , salary , DENSE_RANK() over (order by salary desc) AS Rowno FROM emp) a
Where a.Rowno=3
 
Approach 2: using subquery

SELECT MIN(Salary) from EMP where salary in
(SELECT TOP 3 salary from emp e order by salary desc)

Ebook Download
View all
Learn
View all