> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# ds_theta_union

> Returns a serialized Theta sketch whose distinct count estimates |A∪B|, the union of two input sketches.

Scalar pairwise union of two serialized Apache DataSketches Theta sketches.
Returns a single serialized compact sketch whose distinct count estimates
`|A ∪ B|`. Returns `NULL` if either input is `NULL`.

For an aggregate-style union over many sketches at once, use
[ds\_theta\_combine](/documents/4.2/sql-reference/sql-functions/aggregate-functions/ds_theta_combine.md).

## Syntax

```Haskell theme={null}
VARBINARY ds_theta_union(sketch_a, sketch_b)
```

* `sketch_a`, `sketch_b`: `VARBINARY` compact theta sketches.

## Examples

```SQL theme={null}
SELECT ds_theta_estimate(ds_theta_union(a.sk, b.sk))
FROM cohort_a a JOIN cohort_b b USING (day);
```

## Keywords

DS\_THETA\_UNION, DS\_THETA\_INTERSECT, DS\_THETA\_A\_NOT\_B, DS\_THETA\_COMBINE


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