Advertisements
how we get 3rd highest and 5th highest salary from a table
To find the third largest salary, use the following query:
select SALARY from emp e1 where (3-1) = (select count(distinct (e2.SALARY)) from emp e2 where e2.SALARY>e1.SALARY)
To find the fifth largest salary, use the following query:
select SALARY from emp e1 where (5-1) = (select count(distinct (e2.SALARY)) from emp e2 where e2.SALARY>e1.SALARY)
select * from(select rownum r,ename,sal from(select * from emp order by sal desc))where r=5;
select salary from employee order by salary desc limit 2,1