Skip to main content
Skip to main content

singleValueOrNull

The aggregate function singleValueOrNull is used to implement subquery operators, such as x = ALL (SELECT ...). It checks if there is only one unique non-NULL value in the data. If there is only one unique value, it returns it. If there are zero or at least two distinct values, it returns NULL.

Syntax

Parameters

Returned values

  • The unique value, if there is only one unique non-NULL value in x.
  • NULL, if there are zero or at least two distinct values.

Examples

Query:

Result:

Query:

Result:

Try ClickHouse Cloud for FREE

Separation of storage and compute, automatic scaling, built-in SQL console, and lots more. $300 in free credits when signing up.

Try it for Free