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
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 20, 2011, 7:34 PM EST
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