How do you find the second highest salary in SQL?medium

Type
problem-solving
Topic
second-highest-salary
Frequency
common
Tags
ranking, window-function, salary
Answer

Use a ranking window function or a subquery that finds the maximum below the overall maximum.

Explanation

DENSE_RANK is often safest when duplicates matter: rank salaries descending, then filter rank = 2. Clarify whether ties should count as one rank.

Hint: reason from constraints before calculating.
Follow-upHow would your query change if multiple employees share the second highest salary?