Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Employee table as follows

Name	Salary
Ram     12000
Asif	15000
Suresh	15000
mohan	18000
Bhuva	19000
asif	25500
Pavan	34000


i want to get the third highest salary using the above Employee table.

What I have tried:

(removed repetition)
Posted
Updated 13-Sep-17 6:33am
v3

1 solution

Try:
SQL
WITH myTableWithRows AS (
	SELECT (ROW_NUMBER() OVER (ORDER BY myTable.Salary DESC)) as row,*
	FROM myTable)
SELECT * FROM myTableWithRows WHERE row = 3

Or:
SQL
SELECT * 
FROM (
    SELECT *, ROW_NUMBER() OVER (ORDER BY Salary DESC) AS RowNum
    FROM [MyTable]   
) AS MyDerivedTable
WHERE MyDerivedTable.RowNum = 3
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900