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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted May 22, 2012, 9:15 AM
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
Jean PaulPosted Nov 11, 2011, 5:35 AM
Dhaval PatelPosted Nov 11, 2011, 5:12 AM
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"
VulpesPosted Nov 11, 2011, 5:07 AM
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
TulasiPosted Nov 11, 2011, 5:06 AM
FROM (SELECT DISTINCT TOP 2 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
Jean PaulPosted Nov 11, 2011, 5:05 AM