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
Can we group by two columns in sql?
What is duration in sql profiler trace?
What is sql prepared statement?
How do you sort in sql?
What is the purpose of a secondary key?
What are types of joins?
what is sp_pkeys? : Transact sql
Why we use stored procedure instead of query?
Is sql the best database?
How to display the records between two range in Oracle SQL Plus?
Can I join the same table twice?
What is row_number () in sql?
what does the t-sql command ident_current does? : Transact sql
What are the disadvantages of not performing database normalization?
What is use of term?