# Comparison operators

[Read this page in HTML](https://www.scopedb.io/docs/reference/commands/query-operators/comparison)

Comparison operators test the equality or ordering of two values. Use them in expressions, including `SELECT` and `WHERE`.

Comparisons return `boolean`, or NULL if either input is NULL. Use [`IS` or `IS NOT`](https://www.scopedb.io/docs/reference/functions/conditional-expression/is.md) when NULL values need to compare equal.

Values of the same type compare as follows:

| Type        | Comparison rules                                                                                                          |
| ----------- | ------------------------------------------------------------------------------------------------------------------------- |
| `int`       | Compare numeric values.                                                                                                   |
| `uint`      | Compare numeric values.                                                                                                   |
| `float`     | Compare numeric values. `NaN` is greater than all other non-NULL values and equal to itself. `+0` and `-0` compare equal. |
| `boolean`   | FALSE is less than TRUE.                                                                                                  |
| `string`    | Lexicographic comparison of characters.                                                                                   |
| `binary`    | Lexicographic comparison of bytes.                                                                                        |
| `timestamp` | An earlier timestamp is less than a later timestamp.                                                                      |
| `interval`  | Compare signed durations. For example, -2 seconds is less than -1 second.                                                 |
| `array`     | Lexicographic comparison of elements, starting at index 0.                                                                |
| `object`    | Lexicographic comparison of key-value pairs, with keys sorted from least to greatest.                                     |

Lexicographic comparison uses the first unequal pair of characters, bytes, elements, or key-value pairs to determine which value is less. If one sequence is a prefix of the other, the shorter sequence is less.

`any` values have a defined order that can be used in `ORDER BY`. Matching contained types follow the rules above. Different contained types compare by type, from greatest to least:

```text
object > array > interval > timestamp > boolean > string > binary > float > uint > int
```

In this type ordering, an `int` value is less than a `float` value, regardless of their numeric values. See [semi-structured data types](https://www.scopedb.io/docs/reference/data-types/semi-structured.md#comparison).

## List of comparison operators

| Operator | Syntax   | Description                          |
| -------- | -------- | ------------------------------------ |
| `=`      | `a = b`  | `a` is equal to `b`.                 |
| `!=`     | `a != b` | `a` is not equal to `b`.             |
| `<>`     | `a <> b` | `a` is not equal to `b`.             |
| `>`      | `a > b`  | `a` is greater than `b`.             |
| `>=`     | `a >= b` | `a` is greater than or equal to `b`. |
| `<`      | `a < b`  | `a` is less than `b`.                |
| `<=`     | `a <= b` | `a` is less than or equal to `b`.    |
