To find the third highest salary in a table, you can use a simple ORDER BY and LIMIT clause in SQL.
Write a function to find the third highest salary in a table. Input: Table: +----+--------+ | Id | Salary | +----+--------+ | 1 | 1000 | | 2 | 2000 | | 3 | 3000 | | 4 | 4000 | +----+--------+ Output: 3000
/* The solution below is optimal because it uses a subquery to find the max salary and then uses that value to find the second highest salary. */ SELECT Salary FROM Employee WHERE Salary IN ( SELECT MAX(Salary) FROM Employee WHERE Salary NOT IN ( SELECT MAX(Salary) FROM Employee ) )
The candidate's solution is correct and uses an optimal approach.
Evaluated at: 2022-11-19 06:16:09