I was trying to get nth highest salary from table using subquery and dense_rank method. below are the results for each method.
Subquery Method:
select Top 1 Salary
from (
select top 7 Salary from Employee order by Salary desc
) as Result
order by Salary
This method returns 7th highest salary as: 3000
Dense_Rank Method:
select *
from (
select Salary, DENSE_RANK() Over(order by Salary desc) DRank
from Employee
) as Result
where DRank=7
This method returns 7th highest salary as: 1000
Initial Table data:
Can anyone give me an idea about which method is correct and why?