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

--2 ND HIGHEST SALARY
SELECT MAX(SALARY) FROM HR.EMPLOYEES
WHERE SALARY < (SELECT MAX(DISTINCT(SALARY)) FROM
HR.EMPLOYEES);

--N TH HIGHEST SALARY
SELECT * FROM HR.EMPLOYEES EMP1
WHERE &N=(
SELECT COUNT(DISTINCT(SALARY))
FROM HR.EMPLOYEES EMP2
WHERE EMP1.SALARY<=EMP2.SALARY
);

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we link a sql database to an existing android app?

542


What is the difference between truncate and drop statements?

569


what are null values? : Sql dba

536


what is the difference between char and varchar data types? : Sql dba

528


Show code of a cursor for loop.

576






What is sql*plus?

563


explain the difference between myisam static and myisam dynamic. : Sql dba

507


what is the difference between blob and text? : Sql dba

519


How many sql statements are used?

559


Mention what is the use of function "module procedure" in pl/sql?

558


What is mutating table error?

650


Is there a 64 bit version of ssms?

506


How do you declare a constant?

516


What found sql?

516


How can you save or place your msg in a table?

517