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 the dynamic sql in oracle?

593


hi friends i completed b.com 2004.i have 3y accounting exp. in manufacturing company.now i have completed oracle finance.pls suggest me how will get job in oracle.can i get job in oracle.

1959


Whats the benefit of dbms_stats over analyze?

1490


Explain about achiever in sql?

582


What is bind variable in oracle 11g?

587






Write a syntax for update query in oracle?

614


What is an oracle table?

554


Please explain drop constraint oracle?

623


Explain the use of analyse option in exp command.

584


What happens to the current transaction if the session is killed?

534


What is the Tune Query

1837


What is an oracle database table?

590


How to set up autotrace for a user account?

592


How to unlock the sample user account in oracle?

556


How to check the server version in oracle?

608