To find out the Nth max sal in oracle i\'m using below query
SELECT DISTINCE sal
FROM emp a
WHERE (
SELECT COUNT(DISTINCE sal)
FROM emp b
select min(sal) from (select distinct(sal) from emp order by sal desc) where rownum <=&n;
Inner query select distinct(sal) from emp order by sal desc
will give the below output as given below.
SAL 5000 3000 2975 2850 2450 1600 1500 1300 1250 1100 950 800
without distinct in the above query select sal from emp order by sal desc
output as given below.
SAL 5000 3000 3000 2975 2850 2450 1600 1500 1300 1250 1250 1100 950 800
outer query will give the 'N'th max sal (E.g) I have tried here for 4th Max sal and out put as given below.
MIN(SAL) 2850