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

> Reference material for HLL_COUNT_ESTIMATE

# HLL_COUNT_ESTIMATE

Extracts a cardinality estimate of a single HLL++ sketch that was previously built using the aggregate
function [HLL\_COUNT\_BUILD](/reference-sql/functions-reference/aggregation/hll-count-build).

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
HLL_COUNT_ESTIMATE(<expression>)
```

## Parameters

| Parameter      | Description                                                                                                                   | Supported input types |
| :------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------- |
| `<expression>` | An HLL++ sketch produced by the [HLL\_COUNT\_BUILD](/reference-sql/functions-reference/aggregation/hll-count-build) function. | `BYTEA`               |

## Return Type

`BIGINT`

## Examples

The following example builds an HLL++ sketch from 1,000 unique integers using `HLL_COUNT_BUILD` and estimates the distinct count:

<div className="query-window">
  ```
  SELECT HLL_COUNT_ESTIMATE(HLL_COUNT_BUILD(number)) AS hll_estimate
  FROM GENERATE_SERIES(1, 1000) AS t(number);
  ```

  | hll\_estimate <span>long</span> |
  | :------------------------------ |
  | 983                             |

  <p><span>Rows: 1</span><span>Execution time: 6.16ms</span></p>
</div>

`HLL_COUNT_ESTIMATE` can also be applied to each sketch independently before merging. The following example builds two sketches from overlapping ranges and estimates the cardinality of each:

<div className="query-window">
  ```
  SELECT HLL_COUNT_ESTIMATE(sketch) AS hll_estimate
  FROM (
      SELECT HLL_COUNT_BUILD(n) AS sketch FROM GENERATE_SERIES(1, 500) t(n)
      UNION ALL
      SELECT HLL_COUNT_BUILD(n) AS sketch FROM GENERATE_SERIES(251, 750) t(n)
  ) sketches;
  ```

  | hll\_estimate <span>long</span> |
  | :------------------------------ |
  | 487                             |
  | 497                             |

  <p><span>Rows: 2</span><span>Execution time: 6.18ms</span></p>
</div>

To estimate the combined count across all sketches, use [HLL\_COUNT\_MERGE](/reference-sql/functions-reference/aggregation/hll-count-merge) to merge them first. The two ranges 1–500 and 251–750 share 250 values, giving 750 unique values in total:

<div className="query-window">
  ```
  SELECT HLL_COUNT_ESTIMATE(HLL_COUNT_MERGE(sketch)) AS merged_estimate
  FROM (
      SELECT HLL_COUNT_BUILD(n) AS sketch FROM GENERATE_SERIES(1, 500) t(n)
      UNION ALL
      SELECT HLL_COUNT_BUILD(n) AS sketch FROM GENERATE_SERIES(251, 750) t(n)
  ) sketches;
  ```

  | merged\_estimate <span>long</span> |
  | :--------------------------------- |
  | 730                                |

  <p><span>Rows: 1</span><span>Execution time: 6.21ms</span></p>
</div>
