To find out second highest salary in Sql Server
what is the seconde highest salary of the employee table
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
Jean PaulRank #32 · 38.5K reputationPosted Nov 11, 2011, 12:05 AM EST
TulasiRank #2,544 · 549 reputationPosted Nov 11, 2011, 12:06 AM EST
FROM (SELECT DISTINCT TOP 2 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
VulpesRank #55 · 29.2K reputationPosted Nov 11, 2011, 12:07 AM EST
http://stackoverflow.com/questions/7417415/how-to-get-second-highest-salary-employees-in-a-table
In practice, I think most folks would just do this and then use the second row returned by the query:
SELECT DISTINCT TOP (2) salary FROM employee ORDER BY salary DESC
Dhaval PatelRank #1,023 · 1.9K reputationPosted Nov 11, 2011, 12:12 AM EST
Please click below link for second highest and lowest record find in Sql Server
http://www.c-sharpcorner.com/Blogs/7111/how-to-get-second-highest-and-lowest-record-in-sql-server.aspx
This post help you then mark as "Accepted Answer"
Jean PaulRank #32 · 38.5K reputationPosted Nov 11, 2011, 12:35 AM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted May 22, 2012, 5:15 AM EDT
Select max(salary) from employee where salary NOT IN
(Select max(salary) from employee)
or
General Syntax for Nth highest salary
select distinct(salary) from employee A where n=(select count(distinct(salary)) from employee B where A.salary<=B.salary)
For 2nd highest salary
Here n=2
select distinct(salary) from employee A where 2=(select count(distinct(salary)) from employee B where A.salary<=B.salary)
Thanks