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
Is stored procedure faster than query?
Can a table contain multiple foreign key’s?
What are different methods to trace the pl/sql code?
What are tables and fields?
How does stored procedure reduce network traffic?
Why we use sql profiler?
How to write html code in pl sql?
What is a sql*loader control file?
Describe sql comments?
What does partition by mean in sql?
what is clause? : Sql dba
What is user defined functions?
What does count (*) mean?
Mention what are different methods to trace the pl/sql code?
What is the plv (pl/vision) package offers?