DENSE_RANK is an ANSI-standard window (analytic) function that returns the rank of each row within a result set partition, with equal values receiving the same rank and the next distinct value receiving the immediately following rank (no gaps). It is evaluated after the WHERE, GROUP BY, and HAVING clauses but before the final ORDER BY. Because it is a pure window function, it does not require a GROUP BY and can be combined with other columns in the SELECT list without collapsing rows. Compared with RANK, which skips numbers after ties, DENSE_RANK produces a dense sequence. The function takes no arguments; the ordering and optional partitioning are defined in the OVER clause. It returns a BIGINT or INTEGER depending on the dialect. Caveats: ordering NULLS may affect rank, and window frame clauses are ignored.
RANK, ROW_NUMBER, NTILE, PARTITION BY, ORDER BY, window functions
SQL:2003 (OLAP window functions)
It returns an integer rank for each row within its partition. Identical ORDER BY values share the same rank, and subsequent ranks increase by 1 without gaps.
Choose DENSE_RANK when you need consecutive numbering without holes after ties, such as leaderboards or tier assignments.
Only if the ORDER BY list uniquely identifies each row. If multiple rows share the same ORDER BY values and the tie cannot be broken, rank order among those ties is nondeterministic.
Wrap the ranking query in a common table expression or subquery, then filter on the computed rank, e.g., `WHERE dense_rank <= N`. This preserves all tied rows at the cutoff.