Analytical SQL · SQL problem

Second Highest Salary

A free sql problem from the Ranking and Top-N per Group skill. Read it here, then solve it in the app.

  • Easy
  • SQL problem
  • Free

The problem

Compensation benchmarking needs the company's second highest distinct salary.

Return exactly one row with one column:

columnmeaning
second_highest_salarythe second highest distinct salary, or NULL if there isn't one

If two people share the top salary, the second highest is the next different amount.

How it's graded

  • Your SQL runs on PostgreSQL 18. Run compares your rows with the expected rows on the sample data; Submit runs it against hidden datasets built to catch the classic mistakes.
  • Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.

More problems in Ranking and Top-N per Group

Write the query Second Highest Salary free

No card needed. Lessons, practice questions and easy problems are free forever.

Free plan, no card · 7-day Pro trial · Cancel anytime