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

What is a file delimiter?

555


What is difference between function and trigger?

546


What types of commands can be executed in sql*plus?

551


What does 0 mean in sql?

528


What is consistency?

714






what is collation? : Sql dba

615


Is and as keyword in pl sql?

511


What does := mean in pl sql?

554


what is sql? : Sql dba

557


What are sql objects?

539


What is data type in database?

545


Explain some predefined exceptions.

585


What is the difference between python and sql?

523


Explain the uses of a database trigger?

567


Why sql query is slow?

577