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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are joins in sql?

719


How do I debug a stored procedure?

812


Is mariadb a nosql database?

763


Is pl sql different from sql?

717


What are the benefits of triggers?

896






What are the two different parts of the pl/sql packages?

791


How to create an array in pl/sql?

771


what is the difference between undefined value and null value? : Sql dba

783


What is the maximum size of sqlite database?

726


How do I upgrade sql?

739


What mean sql?

740


State some properties of relational databases?

762


What is left join in postgresql?

750


How do I run a sql trace?

692


Is sql dba a good career? : SQL DBA

712