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


Please Help Members By Posting Answers For Below Questions

Which join is like inner join?

555


What are the most important characteristics of pl/sql?

566


what are all the different types of indexes? : Sql dba

522


Can I copy :old and :new pseudo-records in/to an oracle stored procedure?

658


Explain isolation levels. : Transact sql

571






what are date and time intervals? : Sql dba

558


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 ?

528


How to fetch alternate records from a table?

673


What is the benefit of foreign key?

522


What is clustered index in sql?

580


Which type of cursor is used to execute the dml statement?

522


What is native sql query?

542


Can we change the table name in sql?

527


Can %notfound return null after a fetch?

579


What is faster join or subquery?

503