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 a file delimiter?
What is difference between function and trigger?
What types of commands can be executed in sql*plus?
What does 0 mean in sql?
What is consistency?
what is collation? : Sql dba
Is and as keyword in pl sql?
What does := mean in pl sql?
what is sql? : Sql dba
What are sql objects?
What is data type in database?
Explain some predefined exceptions.
What is the difference between python and sql?
Explain the uses of a database trigger?
Why sql query is slow?