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 to put more than 1000 values into an oracle in clause?

595


If any one has information regarding interview of NIC (National Informatics Centre),it would be of great help...

1741


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.

1971


What is the sid in oracle?

542


Point the difference between translate and replace?

582






Explain a private synonyms?

648


master table and child table performances and comparisons in Oracle ?

1677


What is save point in oracle database?

736


how can we store any pdf file in oracle

1652


How to insert a record into a table?

652


How would you change old and new values in an insert, delete and update triggers?

549


Why do you create or replace procedures rather that drop and recreate.

553


what is the difference between restoring and recovering?

566


What is the purpose of save points in oracle database?

555


Can you tell me how to add new column in existing views?how?How is possible?

948