Query to get max and second max in oracle in one query ?

Answer Posted / bhanu yadav

For Nth Max.

select distinct a.sal from emp a where &N= (select count
(distinct b.sal) from emp b where b.sal>=a.sal)

For Nth Min.

select distinct a.sal from emp a where &N= (select count
(distinct b.sal) from emp b where b.sal<=a.sal)

Is This Answer Correct ?    9 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the use of triggers in Java program? I mean where do we use triggers in Java programming?

1695


What is concurrency in oracle?

547


How to get last row id?

557


What are advantages of dateset in datastage?

1748


What is the difference between online and offline backups?

561






How to invoke the original export import utilities?

507


What do you mean by group by clause?

563


What is a tns file?

502


How to drop a tablespace?

574


For a field in a repeating frame, can the source come from the column which does not exist in the data group which forms the base for the frame ?

1558


what is reindexing?

1179


What are the data types in oracle?

552


How to download oracle database 10g xe?

600


State the various uses of dbcc command?

551


Explain what are the different type of segments?

580