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.

Get the Second highest-largest Value from column

Get the Second highest-largest Value from column

Solution:

Get the Second highest-largest Value from column

Get the Second highest-largest Value from column

Script:

select ename,sal
   from (
select ename, sal,
         row_number()over(order by sal desc) rn
from emp
         ) x
where rn = 2;

One comment

  • Rajindermanhas

    Alternative Script : select min(sal) from(select sal from emp order by sal desc) where rownum<=2