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 ? | 12 Yes | 2 No |
Post New Answer View All Answers
what is primary key? : Sql dba
how to fetch alternate records from a table? : Sql dba
What is pl/sql language case sensitive?
what are the differences between procedure-oriented languages and object-oriented languages? : Sql dba
What is the importance of sqlcode and sqlerrm?
How do I find duplicates in a single column in sql?
How can we avoid duplicating records in a query?
What is use of package in pl sql?
Whis is not false in primary key?
Explain scalar functions in sql?
What is sql not null constraint?
What is a composite primary key?
What is the trigger in sql?
What are sql queries used for?
What is auto increment feature in sql?