How to retrieve a second highest salary from a table?
Note:Suppose salaries are in duplicate values
eg:
Name Sal
Malli 60000
Pandi 60000
Rudra 45000
Ravi 45000
Answer Posted / mallinathabj
The Following queries to retrieve the second highest salary
SQL> select max(sal) from emp where sal<(select
max(distinct(sal)) from emp);
SQL> select min(sal) from(select distinct( sal) from emp order
by sal desc) where rownum<=2;
SQL> SELECT MAX(SAL) FROM EMP WHERE SAL NOT IN (SELECT
MAX(SAL) FROM EMP);
| Is This Answer Correct ? | 13 Yes | 2 No |
Post New Answer View All Answers
What is scope of pl sql developer in future?
What are different types of queries in sql?
what are the differences between get and post methods in form submitting. Give the case where we can use get and we can use post methods? : Sql dba
How do you bind variables in pl sql?
Explain locks? : Transact sql
How does sql profiler work?
How many sql are there?
Explain autonomous transaction.
What is the difference among union, minus and intersect?
What is varray in pl sql?
Define join and name different types of joins?
What is the difference between the conventional and direct path loads? : aql loader
How many indexes can be created on a table in sql?
What is pl sql commands?
What does fetching a cursor do?