Available in versions: Dev (3.21)

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

APPROX_COUNT_DISTINCT

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The APPROX_COUNT_DISTINCT() aggregate function produces an approximatively equivalent value to the COUNT(DISTINCT ..) function, using a faster approximative counting algorithm.

SELECT approx_count_distinct(LANGUAGE_ID)
FROM BOOK
create.select(approxCountDistinct(BOOK.LANGUAGE_ID))
      .from(BOOK)

Producing (for example):

+-----------------------+
| approx_count_distinct |
+-----------------------+
|                     3 |
+-----------------------+

If the function is not supported natively, jOOQ will just fall back to the slower, exact COUNT(DISTINCT ..) function, instead.

For consistency with COUNT(DISTINCT ..), this function returns a java.lang.Integer value. To support larger java.lang.Long result values, use DSL.approxCountLargeDistinct() instead.

Dialect support

This example using jOOQ:

anyValue(BOOK.ID)

Translates to the following dialect specific expressions:

ASE, Access, Aurora Postgres, CockroachDB, DB2, Exasol, Firebird, HSQLDB, Hana, Informix, MariaDB, SQLDataWarehouse, SQLServer, SQLite, Sybase, Teradata, Vertica, YugabyteDB

min(BOOK.ID)

Aurora MySQL, BigQuery, Databricks, DuckDB, H2, MemSQL, MySQL, Oracle, Postgres, Redshift, Snowflake, Spanner

any_value(BOOK.ID)

ClickHouse

any(BOOK.ID)

Trino

arbitrary(BOOK.ID)
Generated with jOOQ 3.21. Support in older jOOQ versions may differ. Translate your own SQL on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo