Forum

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

How to find the second highest salary of an Employee?

2 Posts
1 Users
0 Likes
301 Views
kumar BI
Posts: 12
 kumar BI
Guest
Topic starter
(@kumar BI)
Active Member
Joined: 2 years ago

second-highest salary from employee table

1 Reply
Ram DBA
Posts: 47
 Ram DBA
Guest
(@Ram DBA)
Eminent Member
Joined: 2 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

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: