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
What are the system predefined user roles?
How to omit columns with default values in insert statement in oracle?
How to export data to a csv file?
When do you get a .pll extension in oracle?
How to define an anonymous procedure without variables?
Explain a data segment?
What is the sid in oracle?
What privilege is needed for a user to connect to oracle server?
What are the differences between primary key and unique key?
What do the 9i dbms_standard.sql_txt() and dbms_standard.sql_text() procedures do?
What happens if you use a wrong connect identifier?
What is an Oracle index?
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.
What is a schema in oracle?
How to export data with a field delimiter?