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

what is primary key? : Sql dba

512


how to fetch alternate records from a table? : Sql dba

605


What is pl/sql language case sensitive?

635


what are the differences between procedure-oriented languages and object-oriented languages? : Sql dba

510


What is the importance of sqlcode and sqlerrm?

853






How do I find duplicates in a single column in sql?

539


How can we avoid duplicating records in a query?

568


What is use of package in pl sql?

534


Whis is not false in primary key?

977


Explain scalar functions in sql?

587


What is sql not null constraint?

606


What is a composite primary key?

585


What is the trigger in sql?

540


What are sql queries used for?

538


What is auto increment feature in sql?

625