Query to get max and second max in oracle in one query ?
Answer Posted / mats önnerby
--- Three level query
--- 1. Find and order all distinct salaries
--- 2. Pick the two top salaries
--- 3. Get all information about employees with that salary
select *
from emp
where sal in (
select sal from (
select distinct sal
from emp
order by sal desc)
where rownum <= 2);
---
--- Simple and straight forward but will return
--- several employees in case they have the same salary
---
| Is This Answer Correct ? | 12 Yes | 3 No |
Post New Answer View All Answers
How would you begin to troubleshoot an ORA-3113 error?
Differentiate between function and procedure in oracle.
What is a sub query? Describe its types?
How would you change old and new values in an insert, delete and update triggers?
How to define a cusotmer as a supplier in ORACLE R12
How to count groups returned with the group by clause in oracle?
In SAP ECC 6.0 , under DB02 tcode , Tablespace name to be explain stepy step all the col
What is the sql query to concatenate column values from multiple rows in oracle?
How to add a new column to an existing table in oracle?
Query to retrieve record for a many to many relationship ?
can anyody please send me the dump for Oracle 10g certifications for DBA path?
How to create a testing table in oracle?
How to connect to the server with user account: sys?
What is Java Pool in Oracle?
Which are the five query types available in oracle?