Create table If Not Exists Employee (Id int, Salary int)
Truncate table Employee
insert into Employee (Id, Salary) values ('1', '100')
insert into Employee (Id, Salary) values ('2', '200')
insert into Employee (Id, Salary) values ('3', '300')
+----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+
+---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+
select
(select distinct salary from employee order by `Salary` desc limit 1,1)
as SecondHighestSalary
Runtime: 140 ms, faster than 62.65% of MySQL online submissions forSecond Highest Salary.
Memory Usage: N/A
Runtime: 153 ms, faster than 43.52% of MySQL online submissions forSecond Highest Salary.
Memory Usage: N/A
Runtime: 191 ms, faster than 5.54% of MySQL online submissions forSecond Highest Salary.
Memory Usage: N/A