Nth Highest Distinct Salary
Preview mode. Log in to edit, run, submit, and save progress.
Medium
Nth Highest Distinct Salary
You are given an Employees table with salaries. Write a SQL query to find the 3rd highest distinct salary. If fewer than 3 distinct salary values exist, return an empty result. Return a single column named third_highest_salary. Table: Employees
| Column Name | Type | Description |
|---|---|---|
| id | INT | Primary key |
| name | VARCHAR | Employee name |
| salary | INT | Annual salary |
Examples
Example 1
Distinct salaries in descending order: 90000, 85000, 80000, 75000. The 3rd distinct value is 80000. Note that 85000 appears twice but counts once.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
query.sql