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

Answer Posted / sumit wadhwa

for max

select a.sal
from emp a
where 1=(select distinct(count(b.sal))
from emp b
where a.sal<=b.sal);

for second max

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

Is This Answer Correct ?    33 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

ur a sql devoloper...what is the process in ur company for finding the database BUGS .. seperate DB testers are there? or devr.s are manage? if DB TESTERS in there what is the process

1741


How to delete a column in an existing table?

589


What is ADDM Advisor in Oracle?

656


How to connect ms access to oracle servers?

548


How to revoke create session privilege from a user in oracle?

554






How to use values from other tables in update statements using oracle?

564


What are the different oracle database objects?

584


1) What is ONE_SIZE_FITS_ALL approach? 2) Explain the Common & Variable Header of DATA FILE? 3) What are the Drawbacks to using OMF DB? and the Advantages? 4) List out the Advantages of Undo T.spaces over the Undo SEGMENT? 5) Difference between the Temporary tablespace with TEMPFILE and the Tablespace with TEMPORARY Keyword? 6) What are the situation extents are freeing for reuse.

1603


How to define a cusotmer as a supplier in ORACLE R12

1726


How to insert a new row into a table in oracle?

585


How do I uninstall oracle 11g?

553


How to calculate date and time differences in oracle?

528


How to get maxsal , minsal, ename department wise in single query

1013


Explain joins in oracle?

559


Can a formula column be obtained through a select statement ?

1843