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

Answer Posted / sumit wadhwa

select distinct(a.colname) from table a where &n=(select
count(distinct(b.colname)) from table b where
a.colname<=b.colname);

from this query u can find out Nth MAX in a one query

eg
select distinct(a.sal) from emp a where &n=(select count
(distinct(b.sal)) from emp b where a.sal<=b.sal);

Is This Answer Correct ?    55 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is Virtual Private Database in Oracle?

633


State any two functions of oracle?

644


Typically, where is the conventional directory structure chosen for Oracle binaries to reside?

1591


How to write date and time interval literals in oracle?

588


Why is oracle used?

563






How to write date and time literals in oracle?

564


Differentiate between translate and replace?

637


What is an Oracle Instance?

695


Is oracle a relational database?

531


What is a cursor variable?

588


You have found corruption in a tablespace that contains static tables that are part of a database that is in NOARCHIVE log mode. How would you restore the tablespace without losing new data in the other tablespaces?

1466


Is there any function in oracle similar like group_concat of mysql?

550


What is the parameter mode that can be passed to a procedure?

581


What is bulk copy or bcp in oracle?

619


What is a database schema in oracle?

632