Second highest salary from employees table

This technical problem deals with finding the second highest salary from a table of employees. An example table is given, along with the expected output.

Problem

Write a SQL query to find the second highest salary from the employees table.
Example table:
| id | name  | salary |
|----|-------|--------|
| 1  | John  | 10000  |
| 2  | Jane  | 12000  |
| 3  | David | 11000  |
Expected output:
| id | name  | salary |
|----|-------|--------|
| 2  | Jane  | 12000  |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT * FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1;

/*

The above solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by salary in descending order and then return the second highest salary.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is also efficient, as it uses the ORDER BY and LIMIT clauses to sort the table by salary in descending order and then return the second highest salary.

Evaluated at: 2022-11-27 10:15:54