Reviewed by Aditya Kumar · Last reviewed 2026-03-24
(1) 5th highest: SELECT salary FROM (SELECT DISTINCT salary, DENSE_RANK() OVER (ORDER BY salary DESC) r FROM employees) WHERE r = 5. (2) Employees > manager: SELECT COUNT(*) FROM employees e JOIN employees m ON e.manager_id = m.employee_id WHERE e.salary > m.salary. **Why**:...
(1) 5th highest: SELECT salary FROM (SELECT DISTINCT salary, DENSE_RANK() OVER (ORDER BY salary DESC) r FROM employees) WHERE r = 5. (2) Employees > manager: SELECT COUNT(*) FROM employees e JOIN employees m ON e.manager_id = m.employee_id WHERE e.salary > m.salary. Why: Combine in CTEs if single query needed. Scalability: Both single-pass.
Red Flag: 5th distinct salary vs 5th row—different! Pro-Move: 'DENSE_RANK for distinct salaries; ROW_NUMBER for 5th row.'
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.