---
title: Comparison Functions reference
meta:
    description: Functions for comparing values.
headingMaxLevels: 2
---

# Comparison functions

These functions evaluate the relationship between two values, returning `1` if the comparison is true and `0` if it is false. The result type is always `UInt8`.

Values can be compared if they belong to compatible type groups, such as numbers, strings, dates, or date-times. Tuples and arrays are compared lexicographically, meaning element by element from left to right.

{% callout type="info" %}
Strings are compared byte-by-byte. This can lead to unexpected results with multi-byte UTF-8 characters. A string that is a prefix of another string is considered "less than" the longer string (e.g., 'apple' < 'applepie').
{% /callout %}

## equals

This function checks if two values are identical.

Alias:
- `a = b` (operator)
- `a == b` (operator)

### Syntax

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

### Arguments

- `a`: Any. The first value to compare.
- `b`: Any. The second value to compare.

### Returns

`1` if `a` is equal to `b`, otherwise `0`. `UInt8`.

### Example

```sql
SELECT equals(10, 10);
```

Result:

```result
┌─equals(10, 10)─┐
│              1 │
└────────────────┘
```

## notEquals

This function determines if two values are different.

Alias:
- `a != b` (operator)
- `a <> b` (operator)

### Syntax

```sql
notEquals(a, b)
```

### Arguments

- `a`: Any. The first value to compare.
- `b`: Any. The second value to compare.

### Returns

`1` if `a` is not equal to `b`, otherwise `0`. `UInt8`.

### Example

```sql
SELECT notEquals('hello', 'world');
```

Result:

```result
┌─notEquals('hello', 'world')─┐
│                           1 │
└─────────────────────────────┘
```

## less

This function checks if the first value is strictly less than the second value.

Alias:
- `a < b` (operator)

### Syntax

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

### Arguments

- `a`: Any. The first value to compare.
- `b`: Any. The second value to compare.

### Returns

`1` if `a` is less than `b`, otherwise `0`. `UInt8`.

### Example

```sql
SELECT less(5, 10);
```

Result:

```result
┌─less(5, 10)─┐
│           1 │
└─────────────┘
```

## greater

This function checks if the first value is strictly greater than the second value.

Alias:
- `a > b` (operator)

### Syntax

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

### Arguments

- `a`: Any. The first value to compare.
- `b`: Any. The second value to compare.

### Returns

`1` if `a` is greater than `b`, otherwise `0`. `UInt8`.

### Example

```sql
SELECT greater(20.5, 15.2);
```

Result:

```result
┌─greater(20.5, 15.2)─┐
│                   1 │
└─────────────────────┘
```

## lessOrEquals

This function determines if the first value is less than or equal to the second value.

Alias:
- `a <= b` (operator)

### Syntax

```sql
lessOrEquals(a, b)
```

### Arguments

- `a`: Any. The first value to compare.
- `b`: Any. The second value to compare.

### Returns

`1` if `a` is less than or equal to `b`, otherwise `0`. `UInt8`.

### Example

```sql
SELECT lessOrEquals(7, 7);
```

Result:

```result
┌─lessOrEquals(7, 7)─┐
│                  1 │
└────────────────────┘
```

## greaterOrEquals

This function determines if the first value is greater than or equal to the second value.

Alias:
- `a >= b` (operator)

### Syntax

```sql
greaterOrEquals(a, b)
```

### Arguments

- `a`: Any. The first value to compare.
- `b`: Any. The second value to compare.

### Returns

`1` if `a` is greater than or equal to `b`, otherwise `0`. `UInt8`.

### Example

```sql
SELECT greaterOrEquals(DATE '2023-01-01', DATE '2022-12-31');
```

Result:

```result
┌─greaterOrEquals(toDate('2023-01-01'), toDate('2022-12-31'))─┐
│                                                           1 │
└───────────────────────────────────────────────────────────┘
```
