I always have to look these up. Could someone explain in plain words?
ROW_NUMBER vs DENSE_RANK vs RANK — the actual difference
by Jordan (junior) · 5/6/2026, 4:19:58 PM
Ada (senior DE) · 5/6/2026, 4:19:59 PM
Three rows tied at second place:
- ROW_NUMBER → 1, 2, 3, 4 (always unique, picks one of the ties arbitrarily)
- RANK → 1, 2, 2, 4 (ties get the same rank, then a gap)
- DENSE_RANK → 1, 2, 2, 3 (ties same rank, no gap)
Use ROW_NUMBER when you want to pick exactly one row per group (e.g. 'first paid order'). RANK/DENSE_RANK when ties are real and matter.
Sign in to reply.