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

how may join possible between (requisition with purchase order)

1712


How do I decide when to use right joins/left joins or inner joins or how to determine which table is on which side?

558


What are the various oracle database objects?

688


How to define a data field as not null?

640


What are the numeric comparison operations?

642






What is the difference between the Oracle ODBC driver and a Microsoft ODBC (Open Database Connectivity) Driver?

626


How to invoke the data pump export utility?

574


What are the differences between number and binary_float in oracle?

578


What are the four Oracle system processes that must always be up and running for the database to be useable?

599


What are the predefined tablespaces in a database?

560


How to start a specific oracle instance?

589


Oracle

1869


How to join two tables in a single query using oracle?

576


How to connect to a local oracle 10g xe server?

542


How a tablespace is related to data files?

589