Skip to main content

ROW_NUMBER() (SQL)

A window function that assigns a unique sequential integer to each row within the same window frame, starting with one.

Synopsis

ROW_NUMBER()

Description

ROW_NUMBER assigns a unique sequential integer to each row, starting with one. If multiple rows contain the same value for the window function field, each row is assigned a unique sequential integer.

Examples

The following example assigns numbers in sequential order to each employee (within each department) based on their salary:

SELECT ROW_NUMBER() OVER (PARTITION BY Department ORDER BY Salary) FROM Company.Employee

See Also

FeedbackOpens in a new tab