2020-04-03 13:23:32 +00:00
|
|
|
---
|
2022-08-28 14:53:34 +00:00
|
|
|
slug: /en/sql-reference/functions/comparison-functions
|
2023-04-19 17:05:55 +00:00
|
|
|
sidebar_position: 35
|
2022-04-09 13:29:05 +00:00
|
|
|
sidebar_label: Comparison
|
2020-04-03 13:23:32 +00:00
|
|
|
---
|
|
|
|
|
2022-06-02 10:55:18 +00:00
|
|
|
# Comparison Functions
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
Below comparison functions return 0 or 1 as Uint8.
|
2017-12-28 15:13:23 +00:00
|
|
|
|
|
|
|
The following types can be compared:
|
2023-04-19 15:55:29 +00:00
|
|
|
- numbers
|
|
|
|
- strings and fixed strings
|
|
|
|
- dates
|
|
|
|
- dates with times
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-05-04 16:35:18 +00:00
|
|
|
Only values within the same group can be compared (e.g. UInt16 and UInt64) but not across groups (e.g. UInt16 and DateTime).
|
2023-04-20 10:18:46 +00:00
|
|
|
|
|
|
|
Strings are compared byte-by-byte. Note that this may lead to unexpected results if one of the strings contains UTF-8 encoded multi-byte characters.
|
|
|
|
|
|
|
|
A string S1 which has another string S2 as prefix is considered longer than S2.
|
|
|
|
|
2023-05-23 18:59:08 +00:00
|
|
|
## equals, `=`, `==` operators
|
2023-04-20 10:18:46 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
```sql
|
|
|
|
equals(a, b)
|
|
|
|
```
|
|
|
|
|
|
|
|
Alias:
|
|
|
|
- `a = b` (operator)
|
|
|
|
- `a == b` (operator)
|
|
|
|
|
2023-05-23 18:59:08 +00:00
|
|
|
## notEquals, `!=`, `<>` operators
|
2023-04-20 10:18:46 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
```sql
|
|
|
|
notEquals(a, b)
|
|
|
|
```
|
|
|
|
|
|
|
|
Alias:
|
|
|
|
- `a != b` (operator)
|
|
|
|
- `a <> b` (operator)
|
|
|
|
|
2023-05-23 18:59:08 +00:00
|
|
|
## less, `<` operator
|
2023-04-20 10:18:46 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
```sql
|
|
|
|
less(a, b)
|
|
|
|
```
|
|
|
|
|
|
|
|
Alias:
|
|
|
|
- `a < b` (operator)
|
|
|
|
|
2023-05-23 18:59:08 +00:00
|
|
|
## greater, `>` operator
|
2023-04-20 10:18:46 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
```sql
|
|
|
|
greater(a, b)
|
|
|
|
```
|
|
|
|
|
|
|
|
Alias:
|
|
|
|
- `a > b` (operator)
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-05-23 18:59:08 +00:00
|
|
|
## lessOrEquals, `<=` operator
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
**Syntax**
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
```sql
|
|
|
|
lessOrEquals(a, b)
|
|
|
|
```
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
Alias:
|
|
|
|
- `a <= b` (operator)
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
## greaterOrEquals, `>=` operator
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
**Syntax**
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
```sql
|
|
|
|
greaterOrEquals(a, b)
|
|
|
|
```
|
2017-12-28 15:13:23 +00:00
|
|
|
|
2023-04-20 10:18:46 +00:00
|
|
|
Alias:
|
|
|
|
- `a >= b` (operator)
|