Practice Second Highest Salary
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: Employee(id INT, salary INT). Employee.id is the unique key. Return the second-highest distinct salary as SecondHighestSalary. Return null when fewer than two distinct salaries exist. Repeated salary values occupy one rank, not multiple positions.
Source: Second Highest Salary on LeetCode. Use the original task for its coding environment and submissions.
Examples
# 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 | +---------------------+
Related LeetCode Problems
Practice more problems similar to Second Highest Salary.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.