SQL interview question: Second Highest Salary

Find the Runner-Up Salary

Your company wants to identify the second-highest paid employee to understand compensation distribution.

Write a query to find the second highest unique salary. Return it as second_salary.

Note: If there's no second highest salary, your query should return NULL.

Inspired by classic SQL interview patterns

Tables

employees 37 rows
  • id integer PK
  • first_name text
  • last_name text
  • email text
  • department_id integer → departments
  • salary integer
  • hire_date text
  • manager_id integer → employees
  • title text
idfirst_namelast_nameemaildepartment_idsalaryhire_datemanager_idtitle
1AliceChen[email protected]12500002015-01-15NULLCEO
2RobertMartinez[email protected]21800002016-03-20NULLCEO
3SarahJohnson[email protected]11500002017-06-101VP Engineering

Keep going