Reviewed by Aditya Kumar · Last reviewed 2026-03-24
DENSE_RANK handles ties: SELECT salary FROM (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM employees) t WHERE rk = 3. Subquery MAX approach: nested 3 levels. **Why DENSE_RANK**: Ties get same rank; RANK skips (two 2nd → next is 4th). **Edge case**: Fewer...
DENSE_RANK handles ties: SELECT salary FROM (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM employees) t WHERE rk = 3. Subquery MAX approach: nested 3 levels. Why DENSE_RANK: Ties get same rank; RANK skips (two 2nd → next is 4th). Edge case: Fewer than 3 distinct salaries returns empty. Parameterize: Replace 3 with variable for Nth.
Red Flag: Using ROW_NUMBER for 'Nth highest' when ties exist—gives arbitrary single row. Pro-Move: 'We used DENSE_RANK and handled empty result in application—returned NULL when no 3rd highest.'
According to DataEngPrep.tech, this is one of the most frequently asked SQL interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.