Click here to Skip to main content
13,597,589 members
Rate this:
 
Please Sign up or sign in to 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 13-Sep-17 5:53am
Updated 13-Sep-17 6:33am
v3

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180621.3 | Last Updated 13 Sep 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100