3 ways to find second / Nth Highest salary in SQL server

Опубликовано: 01 Март 2026
на канале: Study Desk of Anand
204
38

Second Highest salary / Nth Highest salary:
In this video, we will see the 3 ways to find out second highest salary or Nth Highest salary.

#sql #bigdata
#programmer #software #coding #database

Link for Analytic function:
   • SQL: Analytic Function  

Link for Dense rank function:
   • SQL: Analytic Function RANK and DENSE_RANK  

Link for sub query:
   • SQL: Sub Query  

SQL code:
-----------------------------


select top 10 salary from Emp_50K
order by 1 desc

select min(salary) sal from (
select top 3 salary from Emp_50K
order by 1 desc
) tbl

--
with cte as (
select t.*, DENSE_RANK() over (order by salary desc) n
from Emp_50K t
) select salary from cte where n = 3
-------------------------------------------------------
Connect to Instagram for any query; thisisanandyadav