---
title: rank ranking window function
description: Learn the syntax of the rank function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/rank
---

# `rank` ranking window function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the rank of a value compared to all values in the partition.

## Syntax

```
rank()
```

## Arguments

This function takes no arguments.

## Returns

An `INTEGER`.

The `OVER` clause of the window function must include an [ORDER BY clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-orderby.md).

Unlike the function `dense_rank`, rank will produce gaps in the ranking sequence.
Unlike `row_number`, rank does not break ties.

If the order is not unique, the duplicates share the same relative earlier position.

## Examples

```sql
> SELECT a,
         b,
         dense_rank() OVER(PARTITION BY a ORDER BY b),
         rank() OVER(PARTITION BY a ORDER BY b),
         row_number() OVER(PARTITION BY a ORDER BY b)
    FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
 A1 1   1   1   1
 A1 1   1   1   2
 A1 2   2   3   3
 A2 3   1   1   1
```

## Related functions

* [`dense_rank` ranking window function](https://docs.databricks.com/aws/en/sql/language-manual/functions/dense_rank.md)
* [`row_number` ranking window function](https://docs.databricks.com/aws/en/sql/language-manual/functions/row_number.md)
* [`cume_dist` analytic window function](https://docs.databricks.com/aws/en/sql/language-manual/functions/cume_dist.md)
* [Window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-window-functions.md)
