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

Answer Posted / ajit

select max(sal),1 no
from emp
union
select sal,rn from (select sal,rownum rn from emp)
where rn = 2
order by 1 desc;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we create database in oracle using command line ?

584


What are the differences between char and nchar in oracle?

603


Explain a segment?

621


What happens to the indexes if a table is recovered?

579


How to lock and unlock a user account in oracle?

618






What operating systems are supported by oracle database 10g xe?

583


what is the difference between data migration and production migration.

1813


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.

1506


How to rename a tablespace in oracle?

621


How can I get column names from a table in oracle?

538


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

549


what is IDE,DMV in sql server?

2252


How can we delete duplicate rows in a table?

568


Why cursor variables are easier to use than cursors?

573


How to store only time; not date and time?

557