Interview SQL Queries – 2


Get second Highest Salary

/* with CTE and window function */
with sec_high as (
select id,
salary,
dense_rank() over ( order by salary desc) as rank_sal
from employee )

select (select distinct salary from sec_high where rank_sal = 2) as SecondHighestSalary from dual;