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 the difference between left outer join and left join?

513


what is bcp? When does it used? : Sql dba

520


Can we write dml inside a function in sql server?

499


Explain what is dbms?

577


What is 19 null in sql?

532






What are pl/sql packages?

568


What is the process of debugging?

549


List the different type of joins?

569


What are the three forms of normalization?

522


What are the types of views in sql?

538


How many types of keys are there in sql?

552


What is right join in sql?

551


Explain cursor types?

578


What is the difference between explicit and implicit cursors in oracle?

514


what is sql in mysql? : Sql dba

569