How to find the second highest salary of an Employee?
second-highest salary from employee table
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
select * from results where results.RNK=2