SQLAdvanced#windows

Difference between ROW_NUMBER, RANK and DENSE_RANK?

ROW_NUMBER always gives unique consecutive numbers. RANK gives ties the same rank and then skips numbers. DENSE_RANK gives ties the same rank with no gaps.

Example
-- salaries 500, 500, 400
ROW_NUMBER -> 1, 2, 3
RANK       -> 1, 1, 3
DENSE_RANK -> 1, 1, 2

Related Questions

1
SQLAdvanced#windows

What do LAG and LEAD do?

Open
2
SQLIntermediate#queries#windows

How do you find the Nth highest salary?

Open
3
SQLIntermediate#queries

How do you find and delete duplicate rows?

Open