Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How many types of table in Oracle?

1172


How oracle handles dead locks?

1130


What exactly do quotation marks around the table name do?

1025


Hi this srilatha. I comlpeted my Oracle-hrms. can u provide me interview questions on Core hr, payroll,sshr,OLM etc..

2148


How to create a table interactively?

1166


What is dual table oracle?

1029


What is rowid and rownum in oracle?

1069


How do I connect to oracle database?

1198


How to generate query output in html format?

1211


Why does for update in oracle 8 cause an ora-01002 error?

1047


Is the After report trigger fired if the report execution fails ?

2952


What is a sub query? Describe its types?

1072


what is dynamic SGA and static SGA

4487


How to find the duplicate rows count from employees table in oracle?

1146


Select all the employees who were hired in last 2 years and who works in dept where max managers are working.

3021