176. second highest salary

SQL Schema

Write a SQL query to get the second highest salary from the Employee table.

1
2
3
4
5
6
7
+----+--------+
| 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.

1
2
3
4
5
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
1
2
3
# Write your MySQL query statement below
# select Salary as SecondHighestSalary from Employee order by Salary DESC limit 1,1
select (Salary) as SecondHighestSalary from Employee where Salary < (select max(Salary) from Employee)