I'm trying to do this Leet Code Problem:
Write a SQL query to get the second highest salary from the Employee table.
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
I'm trying to give this solution:
SELECT
CASE WHEN Salary = ''
THEN NULL
ELSE Salary END SecondHighestSalary
FROM
Employee
ORDER BY
SecondHighestSalary
LIMIT 1,1;
When there is a second salary, it works fine and returns the output. However, when there is no second salary and there's only one salary only an empty string is returned. I'm trying to return NULL, however, it doesn't return NULL like what I wrote in my query. How can I fix this?