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


Please Help Members By Posting Answers For Below Questions

where are cookies actually stored on the hard disk? : Sql dba

786


what is bdb (berkeleydb)? : Sql dba

755


What are different sql data types?

685


How do you update a sql procedure?

767


How can I change database name in sql?

703






Is sql a scripting language?

690


What is string join?

746


How can I see all tables in sql?

727


What is t sql used for?

733


What is sql performance tuning?

651


How you can copy a file to file content and file to pl/sql table in advance pl/sql?

819


what is sql server agent? : Sql dba

772


Is big data nosql?

692


how to present a past time in hours, minutes and seconds? : Sql dba

739


How to select the Nth maximum salary from Table Emp in Oracle SQL Plus ?

814