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
What is mdf ldf and ndf?
What is 19 null in sql?
What is Collation Sensitivity ? What are the various type ?
Show the two pl/sql cursor exceptions.
What is an invalid partition table?
does sql support programming? : Sql dba
What is sql indexing?
What does (+) mean in sql joins?
What is a join?
What is trigger types in sql?
What is pl sql in oracle?
Can we use delete in merge statement?
Enlist the advantages of sql.
When you have to use a default "rollback to" savepoint of plvlog?
Advantages and disadvantages of stored procedure?