Find the Second Highest Salary in a Table

This technical problem involves finding the second highest salary in a table. An example input and output is provided.


Write a SQL query to find the second highest salary from the employees table.
Example input:
| Id | Salary |
| 1  | 1000   |
| 2  | 2000   |
| 3  | 3000   |
Example output:
| Salary |
| 2000   |


This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT MAX(Salary) AS Salary
FROM Employee
WHERE Salary < (SELECT MAX(Salary) FROM Employee)


The solution above is optimal because it uses a subquery to find the maximum salary and then uses that value to find the second highest salary.


A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The candidate has taken a good approach to solving the problem and has provided a complete solution.

Evaluated at: 2022-11-14 12:15:22