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
What is consistency?
How to select 10 records from a table?
What is crud diagram?
What is the execution plan in sql?
how can we take a backup of a mysql table and how can we restore it. ? : Sql dba
What is latest version of sql?
how do you know if your mysql server is alive? : Sql dba
Is a table valued function object?
Is sql a microsoft product?
What is exit statement?
What is sharding in sql?
How exception is different from error?
Are stored procedures faster than queries?
What is the left table in sql?
Is sql free?