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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a trigger? : Sql dba

762


What are sql functions? Describe the different types of sql functions?

756


What are different types of triggers?

738


What is difference between table and view?

706


How do I copy a table in sql?

696






Is sqlite thread safe?

787


What are the string functions in sql?

720


what is sp_pkeys? : Transact sql

889


How to convert comma separated string to array in pl/sql?

812


Can we create index on primary key?

716


What is crud stand for?

746


what is transaction? : Sql dba

719


What is cartesian join in sql?

744


Can we use ddl statements in stored procedure?

881


How do you select unique values in sql?

708