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 / vaibhav

SELECT Sal
FROM (Select Sal from Emp_Salary order by Sal desc)
WHERE rownum < =2;


Above query will fetch two rows. First row is the max salary
and second row second max.

IF we only need to find second max, then

SELECT Min(Sal)
FROM (Select Sal from Emp_Salary order by Sal desc)
WHERE rownum < =2;

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I have a table called 'test' on source and target with same name, structure and data type but in a different column order. How can you setup replication for this table?

1117


Can we call procedure inside function in oracle?

1102


How does the on-delete-cascade statement work?

1117


How to use "startup" command to start default instance?

1042


What is the difference between substr & instr functions?

1233


How to get maxsal , minsal, ename department wise in single query

1552


How to run the anonymous block again?

1135


various types of hints and their usage

2701


What are the predefined tablespaces in a database?

1088


How to convert characters to dates in oracle?

1104


What is a tns file?

1001


How to use "for" statements in oracle?

1077


How to drop an index?

966


What is the difference between PFILE and SPFILE in Oracle?

1065


What is oracle open database communication (odbc)?

1031