Aug 04, 2020 11:07 am
second-highest salary from employee table
1 Reply
Aug 05, 2020 4:21 am
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