ROW_NUMBER
A window function that numbers rows 1, 2, 3 in the window's order, giving tied rows different numbers.
In more detail
Because ties are broken arbitrarily, add a tie-breaker column to the ORDER BY so the numbering is repeatable. It is the usual way to pick the first or latest row in each group.
Related terms
- RANK — A window function that gives tied rows the same position and then skips positions, as in 1, 2, 2, 4.
- DENSE_RANK — A window function that gives tied rows the same position without leaving gaps, as in 1, 2, 2, 3.
- window function — A calculation across a set of rows related to the current row that, unlike GROUP BY, keeps every input row in the answer.
- tie breaker — A final unique field, usually the identifier, added to a sort order so items with equal values always come out in the same order.
Taught in
- Advanced Window Functions: Ranking And Framing — PostgreSQL, Indexing & Relational Data Modeling