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
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?
Can we call procedure inside function in oracle?
How does the on-delete-cascade statement work?
How to use "startup" command to start default instance?
What is the difference between substr & instr functions?
How to get maxsal , minsal, ename department wise in single query
How to run the anonymous block again?
various types of hints and their usage
What are the predefined tablespaces in a database?
How to convert characters to dates in oracle?
What is a tns file?
How to use "for" statements in oracle?
How to drop an index?
What is the difference between PFILE and SPFILE in Oracle?
What is oracle open database communication (odbc)?