12,399,471 members (52,283 online)
Rate this:
See more:
I want to get the second highest salary or say nth highest salary.....pls help?
also how to get record of first n highest salaries?
Posted 8-Aug-11 21:16pm

Rate this:

## Solution 1

Try this.
`Select * from (select  ROW_NUMBER() OVER (ORDER BY Salary DESC) as ID, * from table) as t where ID = n`
n - position of salary
Rate this:

## Solution 2

If you can have duplicates (the same salary more than one time), one way is:
```select c.*
from (select b.onetime,
row_number() over (order by b.onetime desc) position
from (select distinct
a.salary as onetime
from   sometable a) b) c
where c.position = 2```

if you want yo get for example top 5 salaries then change the condition:
`...where c.position <= 5`
Rate this:

## Solution 3

Here you go. Other Alternates

Second highest value[^]
Rate this:

## Solution 4

Try
```select min(Salary) from TableName where Salary in
(select TOP 2 (Salary) from Payroll order by Salary desc)```
Dara Dhillon 9-Aug-11 8:27am

►►this one is really works the best....super like◄◄
Dara Dhillon 9-Aug-11 8:36am

there is limitation i found i.e if two employees have same maximum salary then the command will sort min from top 2 salaries ordered by desc which will give the result same as that of highest salary..
saj_21 28-Jan-13 4:03am

select min(Salary) from TableName where Salary in
(select DISTINCT TOP 2 (Salary) from Payroll order by Salary desc)
Rate this:

## Solution 5

To get second highest salary,
`select max(Salary) from Employee where Salary not in(select max(Salary) from Employee)`
Dara Dhillon 9-Aug-11 8:36am

........ perfect one .......
Rate this:

## Solution 6

SELECT *
FROM emp e
WHERE (2) = (
SELECT COUNT( DISTINCT ( e2.sal ) )
FROM emp e2
WHERE e2.sal >= e.sal
);
Rate this:

## Solution 8

Select max(sal) from emp where sal<(Select max(sal) from emp);

Top Experts
Last 24hrsThis month
 ppolymorphe 400 OriginalGriff 350 Vincent Maverick Durano 265 0x01AA 195 Karthik Bangalore 135
 OriginalGriff 6,723 ppolymorphe 2,835 Karthik Bangalore 2,707 Richard MacCutchan 2,057 F-ES Sitecore 2,052