Forum

How to find the sec...
 
Notifications
Clear all

How to find the second highest salary of an Employee?


kumar BI
Posts: 12
 kumar BI
Topic starter
(@kumar BI)
Joined: 1 year ago

second-highest salary from employee table

1 Reply
Ram DBA
Posts: 47
 Ram DBA
(@Ram DBA)
Joined: 1 year 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
Share: