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
How to drop an existing table in oracle?
What is sharded cluster?
Where is the export dump file located?
How does the on-delete-cascade statement work?
How to save query output to a local file?
What is primefaces used for?
What is an oracle database?
What is a trace file and how is it created in oracle?
How to call a sub procedure?
What is an oracle database table?
How to invoke the data pump export utility?
Explain temporal data types in oracle
How to start instance with a minimal initialization parameter file?
What is index in Oracle?
What is a parameter file in oracle?