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 to assign a table row to a record variable?
How to use fetch statement in a loop?
How can we force the database to use the user specified rollback segment?
What is meant by recursive hints in oracle?
What is logical backup in oracle?
How to apply filtering criteria at group level in oracle?
How to drop an index?
How many data types are supported?
What do you mean by merge in oracle and how can you merge two tables?
How to loop through a cursor variable?
What is the difference between sharding and partitioning?
What is open database communication (odbc) in oracle?
Database crashes. Corruption is found scattered among the file system neither of your doing nor of Oracles. What database recovery options are available? Database is in archive log mode.
Explain the difference between sap and oracle?
how to handle exceptions in post production