How do you retrieve the second highest salary from a table?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / 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 |
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 |
how to get a list of columns in an existing table? : Sql dba
What does desc stand for?
Are views faster than queries?
how can create data base link for tow servers (scott schema) give examples plz
I have a tablle like this. cust acc --------------- a 1 b 2|3 c 4|5|6 I Want below o/p: cust acc ----------- a 1 b 2 b 3 c 4 c 5 c 6 Please any one can you have any ideas share me. I have urgent requirement.
Explain what is rdbms?
What are the commands used in sql?
how can we destroy the session, how can we unset the variable of a session? : Sql dba
who introduced sql?
Is join an inner join?
How many types of relationship are there?
What is Difference Between Unique and Primary Key Constraints?