Finding the Nth Highest Value 🥉
SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET n - 1;
- Use ORDER BY to sort salaries.
- Skip n-1 rows using OFFSET.
SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET n - 1;