---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ydb.tech/docs/en/yql/reference/syntax/select/unique_distinct_hints.md
  - https://ydb.tech/docs/ru/yql/reference/syntax/select/unique_distinct_hints.md
sourcePath: en/core/yql/reference/syntax/select/unique_distinct_hints.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# UNIQUE DISTINCT hints

Directly after `SELECT`, it is possible to add [SQL hints](https://ydb.tech/docs/en/yql/reference/syntax/lexer.md#sql-hints) `unique` or `distinct`, which declare that this projection generates data containing unique values in the specified set of columns of a row-based or columnar table. This can be used to optimize subsequent subqueries executed on this projection, or for writing to table meta-attributes during `INSERT` (currently not supported for columnar tables).

* Columns are specified in the hint values, separated by spaces.
* If the set of columns is not specified, uniqueness applies to the entire set of columns in this projection.
* `unique` - indicates unique or `null` values. According to the SQL standard, each null is unique: `NULL = NULL` -> `NULL`.
* `distinct` - indicates completely unique values including null: `NULL IS DISTINCT FROM NULL` -> `FALSE`.
* Multiple sets of columns can be specified in several hints for a single projection.
* If the hint contains a column that is not in the projection, it will be ignored.
