2020-06-18 08:24:31 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/uniq
2024-06-24 11:52:30 +00:00
sidebar_position: 204
2020-06-18 08:24:31 +00:00
---
2022-06-02 10:55:18 +00:00
# uniq
2020-06-18 08:24:31 +00:00
Calculates the approximate number of different values of the argument.
``` sql
uniq(x[, ...])
```
2021-02-15 21:33:53 +00:00
**Arguments**
2020-06-18 08:24:31 +00:00
The function takes a variable number of parameters. Parameters can be `Tuple` , `Array` , `Date` , `DateTime` , `String` , or numeric types.
**Returned value**
2023-04-19 15:55:29 +00:00
- A [UInt64 ](../../../sql-reference/data-types/int-uint.md )-type number.
2020-06-18 08:24:31 +00:00
**Implementation details**
Function:
2023-04-19 15:55:29 +00:00
- Calculates a hash for all parameters in the aggregate, then uses it in calculations.
2020-06-18 08:24:31 +00:00
2023-04-19 15:55:29 +00:00
- Uses an adaptive sampling algorithm. For the calculation state, the function uses a sample of element hash values up to 65536. This algorithm is very accurate and very efficient on the CPU. When the query contains several of these functions, using `uniq` is almost as fast as using other aggregate functions.
2020-06-18 08:24:31 +00:00
2023-04-19 15:55:29 +00:00
- Provides the result deterministically (it does not depend on the query processing order).
2020-06-18 08:24:31 +00:00
We recommend using this function in almost all scenarios.
**See Also**
2023-04-19 15:55:29 +00:00
- [uniqCombined ](../../../sql-reference/aggregate-functions/reference/uniqcombined.md#agg_function-uniqcombined )
- [uniqCombined64 ](../../../sql-reference/aggregate-functions/reference/uniqcombined64.md#agg_function-uniqcombined64 )
- [uniqHLL12 ](../../../sql-reference/aggregate-functions/reference/uniqhll12.md#agg_function-uniqhll12 )
- [uniqExact ](../../../sql-reference/aggregate-functions/reference/uniqexact.md#agg_function-uniqexact )
- [uniqTheta ](../../../sql-reference/aggregate-functions/reference/uniqthetasketch.md#agg_function-uniqthetasketch )