Query like a pro
SQL Queries
Each problem comes with a plain-English description, the best approach, and a clean, copy-ready query.
Second Highest Salary
MediumSubqueryAggregationGiven an Employee table, report the second highest distinct salary. If there is no second highest salary, return null.
Best Approach
Find the MAX salary, then take the MAX of all salaries strictly less than it. Wrapping in a subquery guarantees a NULL row when only one distinct salary exists.
solution.sql
SELECT MAX(salary) AS SecondHighestSalary
FROM Employee
WHERE salary < (SELECT MAX(salary) FROM Employee);