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 an index in sql with example?
what is the difference between a having clause and a where clause? : Sql dba
What is sql comments?
what is a composite key ? : Sql dba
What is Difference Between Unique and Primary Key Constraints?
how do you know if your mysql server is alive? : Sql dba
Is big data nosql?
How do you add a column to a table?
What is the use of stored procedures?
What are the different schemas objects that can be created using pl/sql?
What is serial sql?
Is it important to partition hard disk?
How to convert comma separated string to array in pl/sql?
explain commit and rollback in mysql : sql dba
Explain the the update statement in sql?