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 difference between post-database commit and post-form commit?
What privilege is needed for a user to create tables in oracle?
How to see free space of each tablespace?
types of indexes and the rationale behind choosing a particular index for a situation.
Explain user account with reference to oracle.
What is concurrency in oracle?
How to use existing values in update statements using oracle?
Which is better Oracle or MS SQL? Why?
What is parameterized cursor in oracle?
What are a query and state the different types of queries and their uses?
How many data types are supported?
How we can able to import our own template (users designed MS-Word templates) which has many tabular columns; need to pass some values generate by Oracle-reports9i? Actually need to import more than 400 MS-Word templates into Oracle Reports-9i to minimize layout design in Reports.
how do u setup a replication site?
Please explain drop constraint oracle?
What is the difference between the Oracle ODBC driver and a Microsoft ODBC (Open Database Connectivity) Driver?