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
Which join is like inner join?
What are the most important characteristics of pl/sql?
what are all the different types of indexes? : Sql dba
Can I copy :old and :new pseudo-records in/to an oracle stored procedure?
Explain isolation levels. : Transact sql
what are date and time intervals? : Sql dba
Table A Table B 1 1 2 1 3 1. Union & union all --> A Union B , A Union all B 2. Minus , Intersect --> A minus B , B Minus A , A Intersect B 3. Joins A join B , A Left Join B A Right Join B , A full Join B 4. %Type - Uses & Benifit 5. Truncate & Delete 6. Pragma Autonomus Transaction 7. how to Perform DDL from function or procedure 8. Can we have DML inside Function 9. Rank & Dense Rank diffrence 10. Water Mark in Oracle 11. Index , Can we have index in all column of table if no then why ?
How to fetch alternate records from a table?
What is the benefit of foreign key?
What is clustered index in sql?
Which type of cursor is used to execute the dml statement?
What is native sql query?
Can we change the table name in sql?
Can %notfound return null after a fetch?
What is faster join or subquery?