12,746,296 members (30,360 online)
Rate this:
See more:
I want a SQL/PLSQL query to find the third highest value for a field (EX:Salary) from my table.
Posted 7-Jan-13 2:06am
Updated 7-Jan-13 2:15am
v2

Rate this:

## Solution 3

v2
Maciej Los 8-Jan-13 13:36pm

Rate this:

## Solution 5

You need to use one of the ranking functions[^].

For example, you can use `ROW_NUMBER()`. Try this:
```DECLARE @myTable TABLE (aValue INT)

INSERT INTO @myTable (aValue)
VALUES(123)
INSERT INTO @myTable (aValue)
VALUES(456)
INSERT INTO @myTable (aValue)
VALUES(789)
INSERT INTO @myTable (aValue)
VALUES(234)
INSERT INTO @myTable (aValue)
VALUES(567)
INSERT INTO @myTable (aValue)
VALUES(345)
INSERT INTO @myTable (aValue)
VALUES(678)
INSERT INTO @myTable (aValue)
VALUES(999)

--view all records
SELECT ROW_NUMBER() OVER(ORDER BY aValue DESC) AS aPosition, aValue
FROM @myTable```

Results:
```1	999
2	789
3	678
4	567
5	456
6	345
7	234
8	123```

```--view only the third highest value
SELECT aValue As [ThirdHighestValue]
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY aValue DESC) AS aPosition, aValue
FROM @myTable
) AS t1
WHERE t1.aPosition = 3```

Result: 678
v2
Rate this:

## Solution 2

Try
```SELECT a.Salary FROM MyTable a
WHERE 3 = (SELECT COUNT(DISTINCT (b.Salary)) FROM MyTable b WHERE a.Salary <= b.Salary)```
Maciej Los 8-Jan-13 13:36pm

Good work, my 5!
__TR__ 9-Jan-13 1:10am

Thank you.
Rate this:

## Solution 4

```SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 3 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary```
v2
Maciej Los 8-Jan-13 13:36pm

Rate this:

## Solution 6

Top Experts
Last 24hrsThis month
 OriginalGriff 285 Peter Leow 210 Karthik Bangalore 185 ppolymorphe 125 Dave Kreskowiak 115
 OriginalGriff 3,558 Peter Leow 2,741 ppolymorphe 1,921 Karthik Bangalore 1,675 Richard MacCutchan 1,319