# ROW\_NUMBER

Returns the number of the current row within its partition.

## Syntax

```
ROW_NUMBER () OVER (
    [PARTITION BY (col | expr), ...]
    [ORDER BY (col | expr), ...]
)

```

## Return Type

An integer

## Examples

```sql
CREATE TABLE rownum_example (a int, b int);

INSERT INTO rownum_example VALUES(1,2),(2,2),(3,3),(4,3);

```

```sql
SELECT a,b, ROW_NUMBER() OVER() FROM rownum_example;


```

```output

+------+------+---------------------+
| a    | b    | row_number() over() |
+------+------+---------------------+
|    1 |    2 |                   1 |
|    2 |    2 |                   2 |
|    3 |    3 |                   3 |
|    4 |    3 |                   4 |
+------+------+---------------------+
```

```sql
SELECT a,b, ROW_NUMBER() OVER(PARTITION BY b ORDER BY a DESC) FROM rownum_example;


```

```output

+------+------+---------------------------------------------------+
| a    | b    | row_number() over(partition by b order by a desc) |
+------+------+---------------------------------------------------+
|    2 |    2 |                                                 1 |
|    1 |    2 |                                                 2 |
|    4 |    3 |                                                 1 |
|    3 |    3 |                                                 2 |
+------+------+---------------------------------------------------+
```

***

Modified at: February 16, 2023

Source: [/db/v9.1/reference/sql-reference/window-functions/row-number/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/window-functions/row-number/)

(An index of the documentation is available at /llms.txt)
