> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DENSE_RANK

> Returns consecutive ranks without gaps for equal ordering values.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Window function</span></div>

Returns a non-NULL rank for every input row.

## Syntax

A window function keeps each input row and adds a result for that row. `PARTITION BY` groups rows with matching values; without it, all input rows form one group.

### Window

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
dense_rank() OVER ([PARTITION BY key] ORDER BY ordering_key)
```

## Arguments

Takes no arguments.

## Returns

* Type: BIGINT
* Possible values: Positive integers starting at 1.
* NULL behavior: Returns a non-NULL rank for every input row.
* Empty input: An empty input produces no rows.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | Yes |
| Supports window frames | No |
| Exact result | Yes |

## Usage notes

* Rows with equal ORDER BY values receive the same rank. Ranking restarts within each PARTITION BY group.
* Explicit window-frame clauses are not supported for this function.

## Examples

### Tied ordering values

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH t("value") AS (VALUES (1), (1), (2), (3)) SELECT "value", dense_rank() OVER (ORDER BY "value") AS result FROM t ORDER BY "value";
```

| value | result |
| - | - |
| 1 | 1 |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |

### Restart the calculation in each group

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH sample(grp, row_id, v) AS (VALUES ('a', 1, 10), ('a', 2, 10), ('a', 3, 20), ('b', 4, 5))
SELECT grp, row_id, v, dense_rank() OVER (PARTITION BY grp ORDER BY v NULLS LAST) AS result
FROM sample ORDER BY grp, row_id;
```

| grp | row\_id | v | result |
| - | - | - | - |
| a | 1 | 10 | 1 |
| a | 2 | 10 | 1 |
| a | 3 | 20 | 2 |
| b | 4 | 5 | 1 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.