SQL command for accessing second highest salary in database
I have salary field in database from which I want to access second highest salary. What can be the command for same
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 Nov 21, 2011, 12:34 AM
Here is your solution.
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
If this post helps you mark it as answer