ROW_NUMBER() OVER ...
All functions > WINDOW FUNCTION > ROW_NUMBER() OVER ...
Returns a unique sequential number for each row within its partition, starting at 1.
Syntax
Diagram(
Sequence(
Terminal("ROW_NUMBER"),
Terminal("("),Terminal(")"),
Terminal("OVER"),
Terminal("("),
NonTerminal("over_clause"),
Terminal(")"),
)
)| Parameter | Type | Required | Description |
|---|---|---|---|
over_clause | OVER CLAUSE | Yes | OVER (PARTITION BY ... ORDER BY ... [FRAME ...]) |
Notes
- Assigns a unique sequential number to each row within a partition
- Numbers start at 1 for the first row in each partition
- Unlike RANK, ROW_NUMBER always assigns unique numbers (no ties)
- ORDER BY determines the sequence of row numbers
- PARTITION BY creates independent numbering groups
- Useful for pagination, deduplication, and selecting top N rows per group
- Always returns consecutive numbers without gaps