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
Can group functions be mixed with non-group selection fields?
What is the difference between PFILE and SPFILE in Oracle?
how may join possible between (requisition with purchase order)
Compare and contrast between sql and sql server and explain its various functions?
What is sharded cluster?
Assuming that you are an End User How to find that in the payment Batch some of the Invoice was Missing To pay How to find That??
What is Reduced List of Values?
What is a private synonym?
How many objectname will be created for a single table drop function? Why 'flashback' query giving error "ORA-38312: original name is used by an existing object" while getting the table?
What is Data Dictionary Cache in Oracle?
How do I spool in oracle?
Does oracle database need java?
HI ALL, CAN ANYONE TELL ME THE DIFFERENCES BETWEEN SQL CLUSTURS,MSQL CLUSTERS,ORACLE CLUSTERS.......THANKS IN ADVANCE
How to write a left outer join with the where clause in oracle?
What is ordinary table in oracle?