SQLIntermediate#queries#windows

How do you find the Nth highest salary?

Either use a correlated MAX with a filter or, preferably, DENSE_RANK inside a subquery so ties are handled correctly.

Example
SELECT salary FROM (
  SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS r
  FROM employees
) t WHERE r = 3;

Related Questions

1
SQLIntermediate#queries

How do you find and delete duplicate rows?

Open
2
SQLIntermediate#queries

How do you find employees earning more than their department average?

Open
3
SQLIntermediate#joins#queries

How do you find records in table A that are missing in table B?

Open