What is the querry for retrieving the 2nd highest salary in a table?
Find out nth highest salary from emp table
Select distinct (a.Sal) from emp a where &n = (select count (distinct (b.Sal)) from emp b where a.Sal < = b.Sal);for eg:-enter value for n: 2sal---------3700
This will work for only highest salary n=1 but not work for 2nd and rest nth salary...
Did you have tried this?
Code
SELECT * FROM (SELECT employee_id, salary, dense_rank() OVER ( ORDER BY salary DESC) r FROM employees) a WHERE a.r =3 ;
Editorial / Best Answer
Answered by: muralir02
View all answers by muralir02
Member Since Mar-2006 | Answered On : Mar 20th, 2006
select max(sal) from emp where sal<(select max(sal) from emp);
select salry from Hello h where 2=(select count (distinct salry) from hello where h.salry