# Comparison (/docs/reference/sql/functions/comparison)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

equals [#equals]

Compares two values for equality.

**Syntax**

```sql
equals(a, b)
        -- a = b
        -- a == b
```

**Arguments**

* `a` — First value.<sup>[\*](#comparison-rules)</sup> - `b` — Second value.<sup>[\*](#comparison-rules)</sup>

**Returned value**

Returns `1` if `a` is equal to `b`, otherwise `0` [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT 1 = 1, 1 = 2;
```

```text title=Response
┌─equals(1, 1)─┬─equals(1, 2)─┐
│            1 │            0 │
└──────────────┴──────────────┘
```

*Introduced in version 1.1.0.*

globalIn [#globalin]

Same as `in`, but uses global set distribution in distributed queries. The set is sent to all remote servers.

**Syntax**

```sql
globalIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 1 IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

globalInIgnoreSet [#globalinignoreset]

Same as `in`, but uses global set distribution in distributed queries. The set is sent to all remote servers.
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
globalIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 1 IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

globalNotIn [#globalnotin]

Same as `notIn`, but uses global set distribution in distributed queries. The set is sent to all remote servers.

**Syntax**

```sql
globalNotIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 4 NOT IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

globalNotInIgnoreSet [#globalnotinignoreset]

Same as `notIn`, but uses global set distribution in distributed queries. The set is sent to all remote servers.
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
globalNotIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 4 NOT IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

globalNotNullIn [#globalnotnullin]

Same as `notNullIn`, but uses global set distribution in distributed queries. The set is sent to all remote servers.

**Syntax**

```sql
globalNotNullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT notNullIn(NULL, tuple(1, NULL))
```

```text title=Response
0
```

*Introduced in version 1.1.0.*

globalNotNullInIgnoreSet [#globalnotnullinignoreset]

Same as `notNullIn`, but uses global set distribution in distributed queries. The set is sent to all remote servers.
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
globalNotNullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT notNullIn(NULL, tuple(1, NULL))
```

```text title=Response
0
```

*Introduced in version 1.1.0.*

globalNullIn [#globalnullin]

Same as `nullIn`, but uses global set distribution in distributed queries. The set is sent to all remote servers.

**Syntax**

```sql
globalNullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT nullIn(NULL, tuple(1, NULL))
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

globalNullInIgnoreSet [#globalnullinignoreset]

Same as `nullIn`, but uses global set distribution in distributed queries. The set is sent to all remote servers.
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
globalNullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT nullIn(NULL, tuple(1, NULL))
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

greater [#greater]

Compares two values for greater-than relation.

**Syntax**

```sql
greater(a, b)
    -- a > b
```

**Arguments**

* `a` — First value.<sup>[\*](#comparison-rules)</sup> - `b` — Second value.<sup>[\*](#comparison-rules)</sup>

**Returned value**

Returns `1` if `a` is greater than `b`, otherwise `0` [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT 2 > 1, 1 > 2;
```

```text title=Response
┌─greater(2, 1)─┬─greater(1, 2)─┐
│             1 │             0 │
└───────────────┴───────────────┘
```

*Introduced in version 1.1.0.*

greaterOrEquals [#greaterorequals]

Compares two values for greater-than-or-equal-to relation.

**Syntax**

```sql
greaterOrEquals(a, b)
    -- a >= b
```

**Arguments**

* `a` — First value.<sup>[\*](#comparison-rules)</sup> - `b` — Second value.<sup>[\*](#comparison-rules)</sup>

**Returned value**

Returns `1` if `a` is greater than or equal to `b`, otherwise `0` [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT 2 >= 1, 2 >= 2, 1 >= 2;
```

```text title=Response
┌─greaterOrEquals(2, 1)─┬─greaterOrEquals(2, 2)─┬─greaterOrEquals(1, 2)─┐
│                     1 │                     1 │                     0 │
└───────────────────────┴───────────────────────┴───────────────────────┘
```

*Introduced in version 1.1.0.*

in [#in]

Checks if the left operand is a member of the right operand set. Returns 1 if it is, 0 otherwise. NULL values in the left operand are skipped (treated as not in the set).

**Syntax**

```sql
in(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 1 IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

inIgnoreSet [#inignoreset]

Checks if the left operand is a member of the right operand set. Returns 1 if it is, 0 otherwise. NULL values in the left operand are skipped (treated as not in the set).
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
in(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 1 IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

isDistinctFrom [#isdistinctfrom]

Performs a null-safe "not equals" comparison between two values.
Returns `true` if the values are distinct (not equal), including when one value is NULL and the other is not.
Returns `false` if the values are equal, or if both are NULL.

**Syntax**

```sql
isDistinctFrom(x, y)
```

**Arguments**

* `x` — First value to compare. Can be any RawTree data type. [`Any`](/reference/data-types)
* `y` — Second value to compare. Can be any RawTree data type. [`Any`](/reference/data-types)

**Returned value**

Returns `true` if the two values are different, treating NULLs as comparable:

* Returns `true` if x != y.
* Returns `true` if exactly one of x or y is NULL.
* Returns `false` if x = y, or both x and y are NULL. [`Bool`](/reference/data-types/boolean)

**Examples**

**Basic usage with numbers and NULLs**

```sql title=Query
SELECT
    isDistinctFrom(1, 2) AS result_1,
    isDistinctFrom(1, 1) AS result_2,
    isDistinctFrom(NULL, 1) AS result_3,
    isDistinctFrom(NULL, NULL) AS result_4
```

```text title=Response
┌─result_1─┬─result_2─┬─result_3─┬─result_4─┐
│        1 │        0 │        1 │        0 │
└──────────┴──────────┴──────────┴──────────┘
```

*Introduced in version 25.11.0.*

isNotDistinctFrom [#isnotdistinctfrom]

Performs a null-safe "equals" comparison between two values.
Returns `true` if the values are equal, including when both are NULL.
Returns `false` if the values are different, or if exactly one of them is NULL.

**Syntax**

```sql
isNotDistinctFrom(x, y)
```

**Arguments**

* `x` — First value to compare. Can be any RawTree data type. [`Any`](/reference/data-types)
* `y` — Second value to compare. Can be any RawTree data type. [`Any`](/reference/data-types)

**Returned value**

Returns `true` if the two values are equal, treating NULLs as comparable:

* Returns `true` if x = y.
* Returns `true` if both x and y are NULL.
* Returns `false` if x != y, or exactly one of x or y is NULL. [`Bool`](/reference/data-types/boolean)

**Examples**

**Basic usage with numbers and NULLs**

```sql title=Query
SELECT
    isNotDistinctFrom(1, 1) AS result_1,
    isNotDistinctFrom(1, 2) AS result_2,
    isNotDistinctFrom(NULL, NULL) AS result_3,
    isNotDistinctFrom(NULL, 1) AS result_4
```

```text title=Response
┌─result_1─┬─result_2─┬─result_3─┬─result_4─┐
│        1 │        0 │        1 │        0 │
└──────────┴──────────┴──────────┴──────────┘
```

*Introduced in version 23.8.0.*

less [#less]

Compares two values for less-than relation.

**Syntax**

```sql
less(a, b)
    -- a < b
```

**Arguments**

* `a` — First value.<sup>[\*](#comparison-rules)</sup> - `b` — Second value.<sup>[\*](#comparison-rules)</sup>

**Returned value**

Returns `1` if `a` is less than `b`, otherwise `0` [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT 1 < 2, 2 < 1;
```

```text title=Response
┌─less(1, 2)─┬─less(2, 1)─┐
│          1 │          0 │
└────────────┴────────────┘
```

*Introduced in version 1.1.0.*

lessOrEquals [#lessorequals]

Compares two values for less-than-or-equal-to relation.

**Syntax**

```sql
lessOrEquals(a, b)
-- a <= b
```

**Arguments**

* `a` — First value.<sup>[\*](#comparison-rules)</sup> - `b` — Second value.<sup>[\*](#comparison-rules)</sup>

**Returned value**

Returns `1` if `a` is less than or equal to `b`, otherwise `0` [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT 1 <= 2, 2 <= 2, 3 <= 2;
```

```text title=Response
┌─lessOrEquals(1, 2)─┬─lessOrEquals(2, 2)─┬─lessOrEquals(3, 2)─┐
│                  1 │                  1 │                  0 │
└────────────────────┴────────────────────┴────────────────────┘
```

*Introduced in version 1.1.0.*

notEquals [#notequals]

Compares two values for inequality.

**Syntax**

```sql
notEquals(a, b)
    -- a != b
    -- a <> b
```

**Arguments**

* `a` — First value.<sup>[\*](#comparison-rules)</sup> - `b` — Second value.<sup>[\*](#comparison-rules)</sup>

**Returned value**

Returns `1` if `a` is not equal to `b`, otherwise `0`. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT 1 != 2, 1 != 1;
```

```text title=Response
┌─notEquals(1, 2)─┬─notEquals(1, 1)─┐
│               1 │               0 │
└─────────────────┴─────────────────┘
```

*Introduced in version 1.1.0.*

notIn [#notin]

Checks if the left operand is NOT a member of the right operand set. Returns 1 if it is not in the set, 0 otherwise. NULL values in the left operand are skipped.

**Syntax**

```sql
notIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 4 NOT IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

notInIgnoreSet [#notinignoreset]

Checks if the left operand is NOT a member of the right operand set. Returns 1 if it is not in the set, 0 otherwise. NULL values in the left operand are skipped.
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
notIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT 4 NOT IN (1, 2, 3)
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

notNullIn [#notnullin]

Checks if the left operand is NOT a member of the right operand set. Unlike `notIn`, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true.

**Syntax**

```sql
notNullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT notNullIn(NULL, tuple(1, NULL))
```

```text title=Response
0
```

*Introduced in version 1.1.0.*

notNullInIgnoreSet [#notnullinignoreset]

Checks if the left operand is NOT a member of the right operand set. Unlike `notIn`, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true.
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
notNullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is not in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT notNullIn(NULL, tuple(1, NULL))
```

```text title=Response
0
```

*Introduced in version 1.1.0.*

nullIn [#nullin]

Checks if the left operand is a member of the right operand set. Unlike `in`, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true.

**Syntax**

```sql
nullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT nullIn(NULL, tuple(1, NULL))
```

```text title=Response
1
```

*Introduced in version 1.1.0.*

nullInIgnoreSet [#nullinignoreset]

Checks if the left operand is a member of the right operand set. Unlike `in`, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true.
This is the IgnoreSet variant used for type analysis without creating the set.

**Syntax**

```sql
nullIn(x, set)
```

**Arguments**

* `x` — The value to check. - `set` — The set of values.

**Returned value**

Returns 1 if x is in the set, 0 otherwise. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Basic usage**

```sql title=Query
SELECT nullIn(NULL, tuple(1, NULL))
```

```text title=Response
1
```

*Introduced in version 1.1.0.*
