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
6. Display the client name and order date for all orders using the traditional method.
What is varray?
How to rename an index in oracle?
How different is ms access and oracle?
What is rowid and rownum in oracle?
Can select statements be used on views in oracle?
In not less than 100 words what's the main difference between Rolap and Molap in ORACLE ?
What are the tools for Oracle ?
How to establish administrator authentication to the server?
Which is better Oracle or MS SQL? Why?
How to run the anonymous block again?
What is the usage of control file in oracle?
What is the usage of save points in oracle database?
How oracle handles dead locks?
what is difference between sql plus and sql*plus? (not sql and sql plus).