SQL
All Top 50 SQL Interview Questions#32
Dynamic Nth Highest Salary Function in SQL
MediumGoogleInterview Question #32
Asked at GoogleWrite 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| id | salary |
|---|---|
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
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.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.