Forum

How to find the sec...
 
Share:
Notifications
Clear all

How to find the second highest salary of an Employee?


Posts: 12
Guest
Topic starter
(@kumar BI)
Active Member
Joined: 4 years ago

second-highest salary from employee table

1 Reply
Posts: 47
Guest
(@Ram DBA)
Eminent Member
Joined: 4 years ago

There are many ways to find the second highest salary of Employees in SQL. You can either use SQL Join or Subquery to solve this problem.

 

Here is SQL query using Subquery:

Select MAX(Salary) from Employee WHERE Salary NOT IN( select MAX(Salary) from Employee

Here is SQL query using Common Table Expression: 

With results as
(

Select ID, Name, salary
, dense_rank over (partition by ID order by salary desc) as RNK
from Employee
)
select * from results where results.RNK=2

Reply

Self Learning Video Tutorials - Software Course

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: