SpinTheMic
Pro

Interview practice question

Second highest salary

Data Engineering · SQL · Beginner

Write a query to find the second highest salary from an employees table. How do you handle ties?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Use DENSE_RANK over salary descending and pick rank 2.
  • DENSE_RANK handles ties correctly.
  • Alternative: MAX(salary) where salary < MAX(salary).
  • Return NULL if there is no second salary.
  • Mention per-department version with PARTITION BY.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics