Arrao4u

…a blog by Rama Rao

Archive for the ‘Top Salary from emp table’ Category

Find top n salary from emp table

Posted by arrao4u on December 12, 2009

Select Min(esal)
From emp
Where  esal In(Select Top n  esal
From emp
Order By esal DESC)

select * from emp x where n+1= (select count(distinct(esal)) from emp where esal>=x.esal)

Ex: if i want to find 2 highest salary from emp table

Select Min(esal)
From emp
Where  esal In(Select Top 2 esal
From emp
Order By esal DESC)

select * from emp x where 3= (select count(distinct(esal)) from emp where esal>=x.esal)

Posted in SqlServer, Top Salary from emp table | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.