Oracle – PL- SQL – Get the Second highest/ largest Value from column
How to get the Second highest/ largest Value from the column ?
Example:
See the table values in the snapshot. As per requirement we need to get second highest/ largest salary form the column sal which is 3000 as per column values.
Solution:
Script:
select ename,sal from ( select ename, sal, row_number()over(order by sal desc) rn from emp ) x where rn = 2;
Alternative Script : select min(sal) from(select sal from emp order by sal desc) where rownum<=2