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 the recommended interval at which to run statspack snapshots, and why?
How to create a new oracle data file?
Where is the export dump file located?
Why do you use stored procedures and state some of its disadvantages?
Using the relations and the rules set out in the notes under each relation, write statements to create the two sequence generators specified in the notes.
while i take backup using ibm tsm the following errors occurred: rman-03009 ora-19513 ora-27206 ora-19502 ora-27030 ora-ora19511
What is a cursor in oracle?
Why we use bulk collect in oracle?
What is a connect identifier?
How to add a new column to an existing table in oracle?
How can I create database in oracle?
How to delete a column in an existing table?
How do you find current date and time in oracle?
What is an Oracle index?
Write a trigger example in oracle?