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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you delete a table?

765


What is a full join?

707


What are the operators used in select statements?

773


What is data definition language?

803


What is linq to sql?

772






Is it possible to create startup or shutdown trigger for on-schema?

780


How do I find duplicates in a single column in sql?

733


What is package in pl sql with an examples?

731


difference between anonymous blocks and sub-programs.

818


Could you please provide oca (oracle 10g) dumps for my certification ?

4782


What is posting?

779


What is structural independence and why is it important?

758


How can you view the errors encountered in a trigger?

735


what is an execution plan? When would you use it? How would you view the execution plan? : Sql dba

728


What is the difference between sum and count in sql?

720