# uniqTheta (/docs/reference/sql/aggregate-functions/uniqtheta)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Calculates the approximate number of different argument values, using the [Theta Sketch Framework](https://datasketches.apache.org/docs/Theta/ThetaSketches.html#theta-sketch-framework).

<details>
  <summary>
    Implementation details
  </summary>

  This function calculates a hash for all parameters in the aggregate, then uses it in calculations.
  It uses the [KMV](https://datasketches.apache.org/docs/Theta/InverseEstimate.html) algorithm to approximate the number of different argument values.

  4096(2^12) 64-bit sketch are used.
  The size of the state is about 41 KB.

  The relative error is 3.125% (95% confidence), see the [relative error table](https://datasketches.apache.org/docs/Theta/ThetaErrorTable.html) for detail.
</details>

**Syntax**

```sql
uniqTheta(x[, ...])
```

**Arguments**

* `x` — The function takes a variable number of parameters. [`Tuple(T)`](/reference/data-types/tuple) or [`Array(T)`](/reference/data-types/array) or [`Date`](/reference/data-types/date) or [`DateTime`](/reference/data-types/datetime) or [`String`](/reference/data-types/string) or [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal`](/reference/data-types/decimal)

**Returned value**

Returns a UInt64-type number representing the approximate number of different argument values. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
CREATE TABLE example_theta
(
    id UInt32,
    category String
)
ENGINE = Memory;

INSERT INTO example_theta VALUES
(1, 'A'), (2, 'B'), (3, 'A'), (4, 'C'), (5, 'B'), (6, 'A');

SELECT uniqTheta(category) as theta_unique_categories
FROM example_theta;
```

```text title=Response
┌─theta_unique_categories─┐
│                       3 │
└─────────────────────────┘
```

*Introduced in version 21.6.0.*
