How do you retrieve the second highest salary from a table?

Answers were Sorted based on User's Feedback



How do you retrieve the second highest salary from a table?..

Answer / nashiinformaticssolutions

Using a subquery:
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Using ROW_NUMBER():
SELECT salary
FROM (
SELECT salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num
FROM employees
) ranked
WHERE row_num = 2;

Is This Answer Correct ?    0 Yes 0 No

How do you retrieve the second highest salary from a table?..

Answer / glibwaresoftsolutions

Using a subquery:
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Using ROW_NUMBER():
SELECT salary
FROM (
SELECT salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num
FROM employees
) ranked
WHERE row_num = 2;

Is This Answer Correct ?    0 Yes 0 No

How do you retrieve the second highest salary from a table?..

Answer / hr@tgksolutions.com

Using a subquery:
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Using ROW_NUMBER():
SELECT salary
FROM (
SELECT salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num
FROM employees
) ranked
WHERE row_num = 2;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

how to get a list of columns in an existing table? : Sql dba

0 Answers  


What does desc stand for?

0 Answers  


Are views faster than queries?

0 Answers  


how can create data base link for tow servers (scott schema) give examples plz

2 Answers  


I have a tablle like this. cust acc --------------- a 1 b 2|3 c 4|5|6 I Want below o/p: cust acc ----------- a 1 b 2 b 3 c 4 c 5 c 6 Please any one can you have any ideas share me. I have urgent requirement.

4 Answers   Cap Gemini, MTS,






Explain what is rdbms?

0 Answers  


What are the commands used in sql?

0 Answers  


how can we destroy the session, how can we unset the variable of a session? : Sql dba

0 Answers  


who introduced sql?

0 Answers  


Is join an inner join?

0 Answers  


How many types of relationship are there?

0 Answers  


What is Difference Between Unique and Primary Key Constraints?

0 Answers   Wipro,


Categories