ClickHouse/docs/en/sql-reference/functions/comparison-functions.md

90 lines
1.3 KiB
Markdown
Raw Normal View History

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
sidebar_label: Comparison
2020-04-03 13:23:32 +00:00
---
2022-06-02 10:55:18 +00:00
# Comparison Functions
2023-04-20 10:18:46 +00:00
Below comparison functions return 0 or 1 as Uint8.
The following types can be compared:
- numbers
- strings and fixed strings
- dates
- dates with times
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-11-26 19:21:39 +00:00
## equals, `=`, `==` operators {#equals}
2023-04-20 10:18:46 +00:00
**Syntax**
```sql
equals(a, b)
```
Alias:
- `a = b` (operator)
- `a == b` (operator)
2023-11-26 19:21:39 +00:00
## notEquals, `!=`, `<>` operators {#notequals}
2023-04-20 10:18:46 +00:00
**Syntax**
```sql
notEquals(a, b)
```
Alias:
- `a != b` (operator)
- `a <> b` (operator)
2023-11-26 19:21:39 +00:00
## less, `<` operator {#less}
2023-04-20 10:18:46 +00:00
**Syntax**
```sql
less(a, b)
```
Alias:
- `a < b` (operator)
2023-11-26 19:21:39 +00:00
## greater, `>` operator {#greater}
2023-04-20 10:18:46 +00:00
**Syntax**
```sql
greater(a, b)
```
Alias:
- `a > b` (operator)
2023-11-26 19:21:39 +00:00
## lessOrEquals, `<=` operator {#lessorequals}
2023-04-20 10:18:46 +00:00
**Syntax**
2023-04-20 10:18:46 +00:00
```sql
lessOrEquals(a, b)
```
2023-04-20 10:18:46 +00:00
Alias:
- `a <= b` (operator)
2023-11-26 19:21:39 +00:00
## greaterOrEquals, `>=` operator {#greaterorequals}
2023-04-20 10:18:46 +00:00
**Syntax**
2023-04-20 10:18:46 +00:00
```sql
greaterOrEquals(a, b)
```
2023-04-20 10:18:46 +00:00
Alias:
- `a >= b` (operator)