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 can we link a sql database to an existing android app?
What is the difference between truncate and drop statements?
what are null values? : Sql dba
what is the difference between char and varchar data types? : Sql dba
Show code of a cursor for loop.
What is sql*plus?
explain the difference between myisam static and myisam dynamic. : Sql dba
what is the difference between blob and text? : Sql dba
How many sql statements are used?
Mention what is the use of function "module procedure" in pl/sql?
What is mutating table error?
Is there a 64 bit version of ssms?
How do you declare a constant?
What found sql?
How can you save or place your msg in a table?