SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal); Output : n=2 , it will display 2nd highest salary from table. Otherwise We can use rank statement to find second largest:
select column1
from
(
select column1 rank() over (order by column1 desc) rank from
(select distinct(column1) from table1)
)
where rank 2;
Simple Solution:
-----------------
Select max(Column1) from table1 where Column1 < (select max(Column1) from table1)
Read More
select column1
from
(
select column1 rank() over (order by column1 desc) rank from
(select distinct(column1) from table1)
)
where rank 2;
Simple Solution:
-----------------
Select max(Column1) from table1 where Column1 < (select max(Column1) from table1)