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


Please Help Members By Posting Answers For Below Questions

How do you explain an index number?

746


what is a view? : Sql dba

814


How do I access sql anywhere database?

673


How is a process of pl/sql compiled?

777


Why we use cross join?

703






What is scalar function?

774


What are character functions in sql?

667


How to pipe multiline string to isql?

758


What trigger means?

730


What is compute?

734


Why plvtab is considered as the easiest way to access the pl/sql table?

834


How do you declare a constant?

708


What is the clause we need to add in function body to return variable?

761


What is full form of rtm?

723


What is the use of desc in sql?

696