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 store only time; not date and time?
Can multiple columns be used in group by in oracle?
What is the difference between the Oracle ODBC driver and a Microsoft ODBC (Open Database Connectivity) Driver?
How can I convert single byte kana characters into multi byte kana characters and vice-versa.
What are the different types of record groups in oracle? Explain each of them
What is ceil and floor in oracle?
When system tablespace is created?
Explain oracle instance.
Can a parameter be passed to a cursor?
What is an oracle function?
Explain what are the characteristics of data files?
Name the various constraints used in oracle?
What is the usage of synonyms?
How to check the server version in oracle?
How to check the oracle tns settings?