> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 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.

# singleValueOrNull

<h2 id="singleValueOrNull">
  singleValueOrNull
</h2>

Introduced in: v21.9.0

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**

```sql theme={null}
singleValueOrNull(x)
```

**Arguments**

* `x` — A column of any data type except Map, Array or Tuple which cannot be of type Nullable. [`Any`](/reference/data-types/index)

**Returned value**

Returns the unique value if there is only one unique non-NULL value in `x`. Returns `NULL` if there are zero or at least two distinct values. [`Any`](/reference/data-types/index) or [`NULL`](/reference/syntax#null)

**Examples**

**Single unique value**

```sql title=Query theme={null}
CREATE TABLE test (x UInt8 NULL) ENGINE=Log;
INSERT INTO test (x) VALUES (NULL), (NULL), (5), (NULL), (NULL);
SELECT singleValueOrNull(x) FROM test;
```

```response title=Response theme={null}
┌─singleValueOrNull(x)─┐
│                    5 │
└──────────────────────┘
```

**Multiple distinct values**

```sql title=Query theme={null}
INSERT INTO test (x) VALUES (10);
SELECT singleValueOrNull(x) FROM test;
```

```response title=Response theme={null}
┌─singleValueOrNull(x)─┐
│                 ᴺᵁᴸᴸ │
└──────────────────────┘
```
