# ROW_NUMBER() Function

### Description

Assigns a unique sequential integer to rows within a partition

### Syntax

```sql
ROW_NUMBER() 
  OVER (
    [PARTITION BY partition_expression]
    ORDER BY sort_expression [ASC | DESC]
  )
```

### Parameters

| Parameter | Description | Data Type | Required |
| --- | --- | --- | --- |
| _PARTITION BY_ | Divides the result set into groups before applying the window function | Clause | No |
| _ORDER BY_ | Defines how rows are ordered within the partition | Clause | Yes |

### Rewrite

Use QUALIFY to filter on window expression results; do not use window functions in WHERE.

#### Notes

-   Include an `OVER (...)` clause with `ORDER BY` (and optional `PARTITION BY`) when using this as a window function.

### Example

```sql
SELECT
    id, ROW_NUMBER() OVER (PARTITION BY department ORDER BY start_date) AS rn
FROM
    rippling.employee.Employee;
```

Source: https://developer.rippling.com/documentation/rippling-platform/transformations/sql-reference/row_number

> For the complete documentation index, see [llms.txt](https://developer.rippling.com/llms.txt). Public pages have a Markdown version at the same URL with .md added.
