a nice set based solution. replace the number '7' with whichever N is of interest
select salary from Employees group by salary
having salary =
(select MIN(top_salary.list) from
(select top 7 distinct_salaries.s as list from
(select distinct salary as s from Employees
group by salary) distinct_salaries
order by distinct_salaries.s desc) top_salary
)
Loading
