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
How do you explain an index number?
what is a view? : Sql dba
How do I access sql anywhere database?
How is a process of pl/sql compiled?
Why we use cross join?
What is scalar function?
What are character functions in sql?
How to pipe multiline string to isql?
What trigger means?
What is compute?
Why plvtab is considered as the easiest way to access the pl/sql table?
How do you declare a constant?
What is the clause we need to add in function body to return variable?
What is full form of rtm?
What is the use of desc in sql?