Description
Write a SQL query to find the second highest salary from the employees table. If there is no second highest salary, return NULL. **Output columns (in order):** salary (or NULL if not found)
Table:
employees| Column | Type |
|---|---|
| id | INT |
| name | TEXT |
| salary | INT |
Examples
Input:
CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1, 'Alice', 50000), (2, 'Bob', 60000), (3, 'Charlie', 55000);Output:
55000Explanation:
Bob has the highest salary at 60000, Charlie has 55000, and Alice has 50000. The second highest distinct salary is 55000 (Charlie's salary). The query must handle finding the second highest value correctly.
Input:
CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1, 'David', 75000), (2, 'Emma', 75000), (3, 'Frank', 65000);Output:
65000Explanation:
When multiple employees share the highest salary (75000), the next distinct salary value is 65000.
Input:
CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1, 'Grace', 80000);Output:
nullExplanation:
Grace is the only employee, so there is no second highest salary and the result is null.
Constraints
- •
Handle edge cases