All subjects

Data · Interview subject

SQL Interview Questions

Joins, aggregates, subqueries and back-end data validation.

54 questions

Quick interview answer

Use DENSE_RANK() in a subquery, or the classic MAX with a nested exclusion.

Detailed explanation

Window functions handle duplicates correctly and scale to Nth highest. Be ready to explain the difference between RANK, DENSE_RANK and ROW_NUMBER.

sql
1SELECT salary
2FROM (
3 SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
4 FROM employees
5) t
6WHERE rnk = 2;

Real-world example

Data validation tests comparing UI leaderboards against the database.

Interview tip

Offer the Nth-highest generalisation before they ask for it.

Next subjectManual Testing