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

What are the system predefined user roles?

586


How to omit columns with default values in insert statement in oracle?

579


How to export data to a csv file?

627


When do you get a .pll extension in oracle?

679


How to define an anonymous procedure without variables?

553






Explain a data segment?

650


What is the sid in oracle?

538


What privilege is needed for a user to connect to oracle server?

559


What are the differences between primary key and unique key?

515


What do the 9i dbms_standard.sql_txt() and dbms_standard.sql_text() procedures do?

4021


What happens if you use a wrong connect identifier?

504


What is an Oracle index?

1179


Assuming today is Monday, how would you use the DBMS_JOB package to schedule the execution of a given procedure owned by SCOTT to start Wednesday at 9AM and to run subsequently every other day at 2AM.

1505


What is a schema in oracle?

547


How to export data with a field delimiter?

582