How to Find Nth Highest Salary Record In Sql Server

This is most frequentky asked question how to select or get nth highest record or nth row/record from any column of sql table.

The following query is shows about select 2nd Highest salary record from emp table in sqlserver

2nd Highest salary:
select top 1 sal from (select top 2 sal from emp order by sal desc)temp order by sal

The following query is shows about select 3rd Highest salary record from emp table in sqlserver

3rd Highest salary:
select top 1 sal from (select top 3 sal from emp order by sal desc)temp order by sal

0 comments:

Post a Comment