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 / praveenpinfo

Suppose table name is EMP.

SQL> Select distinct sal from emp e1 where 2=(select
count(distinct sal) from emp e2 where e1.sal<=e2.sal);

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we use ddl statements in stored procedure?

696


Can a table contain multiple foreign key’s?

575


Does execute immediate commit?

700


What are synonyms in sql?

534


Which tcp/ip port does sql server run?

534






What are the different types of triggers?

593


Is coalesce faster than isnull?

508


What is sql indexing?

555


What is the source code of a program?

507


Do triggers have restrictions on the usage of large datatypes, such as long and long raw?

688


what are all different types of collation sensitivity? : Sql dba

525


how are mysql timestamps seen to a user? : Sql dba

564


What are the two types of exceptions in pl/sql?

546


What is schema in sql example?

596


what is a control file ? : Sql dba

577