@ Leetcode : 176. Second Highest Salary | Amazon, Apple

Company : Amazon, Apple

Question :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 |
+---------------------+

My Solution :

Runtime: 179 ms, faster than 70.95% of MySQL online submissions for Second Highest Salary.

Memory Usage: 0B, less than 100.00% of MySQL online submissions for Second Highest Salary.

SQL Query :

select max(Salary) as SecondHighestSalary from Employee where Salary not in(select max(Salary) from Employee )

--

--