Pages

Monday, February 8, 2010

SQL SERVER – Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value

This question is quite a popular question and it is interesting that I have been receiving this question every other day. I have already answer this question here. “How to find Nth Highest Salary of Employee”.

How to get 1st, 2nd, 3rd, 4th, nth topmost salary from an Employee table

The following solution is for getting 5th highest salary from Employee table ,

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 5 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary


If you want to retrieve a nth Maximum value then use nth value instead of 5 and enjoy!!!!!!!

Cheers

5 comments:

Anonymous said...

Hi Guru,
Nice Post,

Keep writing useful post like this.

Thanks & Regards
Ramani Sandeep

Dr. Parag Shukla said...

Thank you very much dear

Anonymous said...

what is the use of 'a' in your query

chennakrishna said...

what is the "a"

Dr. Parag Shukla said...

"a" is an alias for temporary data.

Post a Comment