Forum

How to find 5 th hi...
 
Notifications
Clear all

How to find 5 th highest salary from employee table?


VK
Posts: 17
 VK
Topic starter
(@vinodkrsetty5895)
Active Member
Joined: 1 year ago

Hi ,

Can anyone help me with how to find 5 the highest salary in the employee table? 

1 Reply
Rakesh
Posts: 47
 Rakesh
(@Rakesh)
Joined: 1 year ago

There are different ways to achieve this. However, I prefer a common table expression in order to capture the highest salaries from a table. 

Let us say I want to capture top 5 employees from the employee table based on their salary. Using common table expression I can write a query something like...

With Results As

(
Select Empno, Ename,Sal,
Dense_Rank() Over (Order by Sal Desc) As DenseRank
)

Select * from Results where Results.DenseRank<=5

Note: Make sure to use dense rank because it won't skip the ranks when there is repeated data. 

I hope it helps. Thank You. 🙂 

Reply
Share: