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 create a menu in sqlplus or pl/sql?
Question: Below is the table city gender name delhi male a delhi female b mumbai male c mumbai female d delhi male e I want the o/p as follows: male female delhi 2 1 mumbai 1 1 Please help me in writing the query that can yield the o/p mentioned above?
List out the acid properties and explain?
How to set up sql*plus output format in oracle?
What is sql key?
What is the maximum rows in csv?
Why do we need cursor in pl sql?
how to rename an existing column in a table? : Sql dba
what are the advantages and disadvantages of views in a database? : Sql dba
What are the benefits of pl/sql packages?
which tcp/ip port does sql server run on? : Sql dba
What is coalesce in sql?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)