how to get second highest sal of emp table

Answer Posted / prabhudatta barick

--IN ORDER TO FIND THE NTH HIGHEST SALARY,
--WE JUST FIND THE SALARY THAT HAS EXACTLY N-1 SALARIES
GREATER THAN ITSELF---

--This is correlated subquery--
select empno,
ename,
sal
from scott.emp e
where &n-1=(select count(distinct b.sal) from scott.emp b
where b.sal>e.sal);

To get second highest salary put n value 2.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the uses of Database Trigger ?

1105


Can we protect our pl/sql source code?

580


What is merge in oracle?

562


Explain enable novalidate constraint.

597


Explain view?

577






What is the Tune Query

1847


Explain the use of control file?

658


ABOUT IDENTITY?

1566


Please explain oracle data types with examples?

590


How to use null as conditions in oracle?

584


Is it possible to split the print reviewer into more than one region ?

1837


What is archive log in Oracle?

603


List out the difference between commit, rollback, and savepoint?

622


When do you get a .pll extension in oracle?

679


How to add a new column to an existing table in oracle?

588