SQLSQL
#32

Dynamic Nth Highest Salary Function in SQL

MediumGoogle
Interview Question #32
Asked at Google

Write a SQL query to get the Nth highest distinct salary from the `employee` table. If there are fewer than N distinct salaries, return `NULL`.

Input Table: employee (N=2)
3 rows preview
idsalary
1100
2200
3300
Expected Output Structure1 rows
getNthHighestSalary(2)
200
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us