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 table in a database ? : Sql dba
name 3 ways to get an accurate count of the number of records in a table? : Sql dba
What is pl sql collection?
Is left join and outer join same?
how many values can the set function of mysql take? : Sql dba
What is character functions?
How to get help at the sql prompt?
How do you remove duplicate records from a table?
How do you drop a trigger?
Name some usages of database trigger?
What is rename in sql?
How exception is different from error?
How do you modify a column in sql?
What is data control language?
Can we use the cursor's to create the collection in PL/SQL?