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

# Uniqueness test

> Detect values that appear more than once in a column or expression.

Validates that a column or expression has no duplicate values. Use it for primary keys, natural keys, and any value that should identify a single row.

This is a [SQL data test](https://docs.elementary-data.com/cloud/features/data-tests/sql-data-tests.md): Elementary runs it against your warehouse on a schedule, with no SQL to write and no pull request.

> [!NOTE]
>
> SQL-based cloud tests read table data, so they need **data access** for the environment's warehouse connection. Data access is enabled in one of two ways:
>
> * Elementary enables data access on the warehouse connection. Contact the Elementary team to turn it on.
> * You connect an [Elementary Runtime](https://docs.elementary-data.com/cloud/features/elementary-runtime.md) to the warehouse connection.
>
> Until data access is available, these tests are hidden from the test catalog.

## How it works

On each run, Elementary groups the table by the tested value and returns every value that appears more than once, together with the number of times it appears.

* **Failing rows are duplicated values.** If the value `1042` appears in three rows, it counts as one failing row with a duplicate count of 3.
* **Nulls are ignored.** Rows where the value is null are never counted as duplicates. To require a value in every row, add a [completeness test](https://docs.elementary-data.com/cloud/features/data-tests/sql-data-tests/completeness.md).
* **The `where` clause applies before grouping.** Only rows that match the condition are compared with each other.

Results count toward the **Uniqueness** [data quality dimension](https://docs.elementary-data.com/cloud/features/collaboration-and-communication/data-quality-dimensions.md).

## Configuration

| Setting | Description |
| - | - |
| **Tested field** | The column, or an expression, whose values should be unique |
| **Where clause** | Optional condition that limits the rows checked |

Severity, thresholds, sampled rows, and cadence work the same for all SQL data tests. See [Configuration](https://docs.elementary-data.com/cloud/features/data-tests/sql-data-tests.md#configuration).

## Examples

| Goal | Tested field | Where clause |
| - | - | - |
| Order IDs are unique | Column `order_id` | — |
| One row per customer per day | Expression `customer_id \|\| '-' \|\| cast(order_date as varchar)` | — |
| Emails are unique regardless of case | Expression `lower(email)` | — |
| Active subscriptions are unique per account | Column `account_id` | `status = 'active'` |

## Example result

The sample lists each duplicated value and its count:

| value | duplicate\_count |
| - | - |
| 1042 | 3 |
| 2210 | 2 |

The failing-row count for this result is 2: two values are duplicated.

## dbt equivalent

The dbt [`unique`](https://docs.getdbt.com/reference/resource-properties/data-tests#unique) test checks the same rule from your dbt project. For a combination of columns, use an expression here, or `dbt_utils.unique_combination_of_columns` in dbt. See [Cloud tests or dbt tests](https://docs.elementary-data.com/cloud/features/data-tests/cloud-or-dbt-tests.md) to decide which to use.


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