304 North Cardinal St.
Dorchester Center, MA 02124

# Second Highest Salary LeetCode Solution

## Problem – Second Highest Salary LeetCode Solution

SQL Schema

Table: `Employee`

``````+-------------+------+
| Column Name | Type |
+-------------+------+
| id          | int  |
| salary      | int  |
+-------------+------+
id is the primary key column for this table.
Each row of this table contains information about the salary of an employee.
``````

Write an SQL query to report the second highest salary from the `Employee` table. If there is no second highest salary, the query should report `null`.

The query result format is in the following example.

Example 1:

``````Input:
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1  | 100    |
| 2  | 200    |
| 3  | 300    |
+----+--------+
Output:
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200                 |
+---------------------+
``````

Example 2:

``````Input:
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1  | 100    |
+----+--------+
Output:
+---------------------+
| SecondHighestSalary |
+---------------------+
| null                |
+---------------------+``````

## Second Highest Salary LeetCode Solution in MySQL

``````select max(Salary) as SecondHighestSalary from Employee
where Salary < (select max(Salary) from Employee)
``````

## Second Highest Salary LeetCode Solution in Oracle

``````select max(Salary) as SecondHighestSalary from Employee where Salary < (select max(Salary) from Employee);
``````

## Second Highest Salary LeetCode Solution in MS SQL Server

``````SELECT IFF(COUNT(id) >= 1, MAX(salary), null) as SecondHighestSalary from Employee
WHERE salary < (SELECT MAX(salary) from Employee)
``````
##### Second Highest Salary LeetCode Solution Review:

In our experience, we suggest you solve this Second Highest Salary LeetCode Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Second Highest Salary LeetCode Solution

Find on Leetcode

##### Conclusion:

I hope this Second Highest Salary LeetCode Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions