Hi,
What is SQL statement for getting n'th highest salary?
Thanks.
SQL statement for getting highest salary
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dhaval PatelRank #1,023 · 1.9K reputationPosted Jan 20, 2012, 2:16 AM EST
use this query for nth Highest Salary
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)
use below link for your reference
http://blog.sqlauthority.com/2008/04/02/sql-server-find-nth-highest-salary-of-employee-query-to-retrieve-the-nth-maximum-value/
http://www.c-sharpcorner.com/Blogs/7111/how-to-get-second-highest-and-lowest-record-in-sql-server.aspx
thanks & Regards
Dhaval Patel
This post help you than Mark As Accepted Answer
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 22, 2012, 6:15 PM EST
try this.
select * from(
SELECT empId, salary,
ROW_NUMBER()OVER(PARTITION BY salary ORDER BY salary ) as RowNum
from ExaminationOptions) A
where A.RowNum =n
order by a.rownum desc
hope this help.