how to find third highest salary in sql code example
Example 1: nth highest salary
SELECT salary FROM Employee ORDER BY salary DESC LIMIT N-1, 1
Example 2: n highest salary in sql
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP N salary
FROM
ORDER BY salary DESC
) AS temp
ORDER BY salary
Example 3: sql find second highest salary employee
select sal, ename
from emp
where sal =
(
select max(sal) from emp where sal <
(select max(sal) from emp)
)
select *
from
(
select ename, sal, dense_rank() over(order by sal desc) rank
from emp
)
where rank =2;