2nd, 3rd, Nth Highest Salary In SQL Server 2008
In this article I will explain, how to find 2nd,3rd, nth highest salary in sql server.
In SQL Server we have the concept about sub queries. Sub queries means query within the query. Lets take a example of sub query. Suppose we want to find out the nth largest salary among the given salaries so for this purpose we have to use sub query.
Lets have a look on the following example.
I have created Employee table with following values.
To select 2nd highest salary or record we can use following query.
To select 3rd highest salary or record we can use following query.
To select nth largest salary or record from above table, we can use following query.
select top 1 salary from (select distinct top n salary from Employee order by salary desc) a order by salary