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

Answer Posted / lokanath

select * from emp a where 2 > (select count(distinct sal)
from emp b where b.sal > a.sal)
or else use Top Window functions (or) Analatical functions
select * from
(
select empno,ename,sal,rank() over (order by sal desc)
test from emp
)
where test <= 2

Is This Answer Correct ?    12 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many types of segments in Oracle?

527


Explain the use of log option in exp command.

533


Why do we need oracle client?

507


How to create a new table by selecting rows from another table?

548


How to assign query results to variables?

588






What is an oracle tablespace?

600


What are the most common interview questions on ETL Testing for experience?

589


What will be the syntax to find current date and time in format "yyyy-mm-dd"?

566


How to establish administrator authentication to the server?

556


What to do if the startbd.bat failed to start the xe instance?

607


What is the relationship among database, tablespace and data file?

537


How to update values in a table in oracle?

579


How to install oracle database 10g xe?

560


What is the relation of a user account and a schema in oracle?

583


What is the difference between count (*), count (expression), count (distinct expression)?

556