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 are extents allocated to a segment?
When do I need to use a semicolon vs a slash in oracle sql?
How would you best determine why your MVIEW couldnt FAST REFRESH?
How do I escape a reserved word in oracle?
Describe the types of sub query?
How i can handle exception in large code like 1000 line without distrubing the code or without exception handler sction?
Difference between inner join vs where ?
What is java oracle used for?
What are the different types of modules in oracle forms?
What query tells you how much space a tablespace named test is taking up, and how much space is remaining?
What is execute immediate in oracle?
How to pass a cursor variable to a procedure?
What is Reduced List of Values?
What happens to the current transaction if the session is killed?
What is merge statement used for?