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
What is an oracle data file?
What is logical backup in oracle?
How to write text literals in oracle?
What is background process in Oracle?
How to end the current transaction in oracle?
What is truncate oracle?
How to pass a parameter to a cursor in oracle?
I have a database backup file in .db (ext) form how to conver it into .dmp (ext.) for oracle database
What is hot backup and logical backup?
How do I use os authentication with weblogic jdriver for oracle and connection pools?
How can Oracle users be audited?
How to create a single index for multiple columns?
What are oracle functions?
How to define and use table alias names in oracle?
what is port in oracle? how is it related to database application.