Search This Blog

Tuesday, November 15, 2011

Find Nth Highest Salary of Employee in Sql server

How to get 2nd, 3rd, 4th, nth topmost salary from an Employee table.
we can get top salary in 2 ways


select top 1 salary from
( select distinct top n salary from Employee order by salary desc ) a
order by Salary

select * from Employee e where n-1 =
(select count(Salary) from Employee f where e.EmpId <= f.EmpId)                                           -- this query won't work for 1st highest salary

In the above query  n = 2nd, 3rd ..... nth salary as per your requirement
Post a Comment

Popular Posts