SQLRANKDENSE_RANKwindow

What are RANK and DENSE_RANK in SQL? Ranking with ties for beginners

RANK and DENSE_RANK are ranking functions where equal values get equal ranks. Plain words: the difference between ROW_NUMBER (always unique), RANK (ties get equal rank with gaps after), and DENSE_RANK (equal rank without gaps). With tables, an Olympic-style example, and common pitfalls.

1 min readSQL · RANK · DENSE_RANK · window · tutorial

RANK and DENSE_RANK are window functions for ranking with ties. Equal values get equal ranks. The difference between them is what happens after the tie — RANK leaves a gap, DENSE_RANK doesn't.

This article is currently in Russian. The full English translation is on the way.

Practice on real tasks

Solve tasks in the SQL trainer with instant grading and hints.

Open trainer