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 many types of table in Oracle?
How oracle handles dead locks?
What exactly do quotation marks around the table name do?
Hi this srilatha. I comlpeted my Oracle-hrms. can u provide me interview questions on Core hr, payroll,sshr,OLM etc..
How to create a table interactively?
What is dual table oracle?
What is rowid and rownum in oracle?
How do I connect to oracle database?
How to generate query output in html format?
Why does for update in oracle 8 cause an ora-01002 error?
Is the After report trigger fired if the report execution fails ?
What is a sub query? Describe its types?
what is dynamic SGA and static SGA
How to find the duplicate rows count from employees table in oracle?
Select all the employees who were hired in last 2 years and who works in dept where max managers are working.