Forum

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

How to find 5 th highest salary from employee table?


Posts: 18
 VK
Topic starter
(@vinodkrsetty5895)
Active Member
Joined: 4 years ago

Hi ,

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

1 Reply
Posts: 47
Guest
(@Rakesh)
Eminent Member
Joined: 4 years 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

Self Learning Video Tutorials - Software Course

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: