---
title: "Logical operators"
description: "CoraDB logical operators AND (&&), OR, XOR and NOT (!), with their three-valued truth table for TRUE, FALSE and NULL, and how numbers are treated as booleans."
url: "https://www.coradb.ai/manual/sql/function/logical_op.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/function/logical_op.md"
product: "CoraDB"
version: "1.0"
keywords: "logical operators, and, or, xor, not, truth table, three-valued logic, null, coradb"
---

# Logical operators

Logical operators combine conditions. Their operands are boolean expressions or numbers: 0 is false, any other number is true, and `NULL` is unknown. The result is 1 (true), 0 (false) or `NULL`.

| Operator | Result |
|---|---|
| `AND`, `&&` | True if both operands are true. |
| `OR` | True if at least one operand is true. |
| `XOR` | True if exactly one operand is true; `NULL` if either operand is `NULL`. |
| `NOT`, `!` | True if the operand is false, and false if it is true. |

`||` means `OR` only when the [pipes_as_concat](https://www.coradb.ai/manual/admin/config_sql.html#statementtype-related-parameters) parameter is `no`. By default it is `yes`, and `||` concatenates strings: `'a' || 'b'` returns `'ab'`.

## Truth table

| a | b | A AND b | A OR b | A XOR b | NOT a |
|---|---|---|---|---|---|
| TRUE | TRUE | TRUE | TRUE | FALSE | FALSE |
| TRUE | FALSE | FALSE | TRUE | TRUE | FALSE |
| TRUE | NULL | NULL | TRUE | NULL | FALSE |
| FALSE | TRUE | FALSE | TRUE | TRUE | TRUE |
| FALSE | FALSE | FALSE | FALSE | FALSE | TRUE |
| FALSE | NULL | FALSE | NULL | NULL | TRUE |
| NULL | NULL | NULL | NULL | NULL | NULL |

```sql
SELECT (1 AND NULL), (0 AND NULL), (1 OR NULL), (0 OR NULL), (1 XOR 0), (NOT NULL), (2 AND 3)
FROM db_root;
```

| (1 AND NULL) | (0 AND NULL) | (1 OR NULL) | (0 OR NULL) | (1 XOR 0) | (NOT NULL) | (2 AND 3) |
|---|---|---|---|---|---|---|
| NULL | 0 | 1 | NULL | 1 | NULL | 1 |

In a `WHERE` clause, a row is returned only when the condition is true; rows for which it is false or `NULL` are left out.

## See also

- [Comparison operators](https://www.coradb.ai/manual/sql/function/comparison_op.html)
- [Operators and functions overview](https://www.coradb.ai/manual/sql/function.html)
