Learn about logical operators in MariaDB Server SQL. This section details operators like AND, OR, and NOT used to combine or negate conditions, essential for complex filtering and data selection.
SELECT 1 && 1;
+--------+
| 1 && 1 |
+--------+
| 1 |
+--------+
SELECT 1 && 0;
+--------+
| 1 && 0 |
+--------+
| 0 |
+--------+
SELECT 1 && NULL;
+-----------+
| 1 && NULL |
+-----------+
| NULL |
+-----------+
SELECT 0 && NULL;
+-----------+
| 0 && NULL |
+-----------+
| 0 |
+-----------+
SELECT NULL && 0;
+-----------+
| NULL && 0 |
+-----------+
| 0 |
+-----------+NOT, !Logical NOT. Evaluates to 1 if the operand is 0, to 0 if the operand is non-zero, and NOT NULL returns NULL.
By default, the ! operator has a . If the HIGH_NOT_PRECEDENCE flag is set, NOT and ! have the same precedence.
This page is licensed: GPLv2, originally from
XORXOR stands for eXclusive OR. Returns NULL if either operand is NULL. For non-NULL operands, evaluates to 1 if an odd number of operands is non-zero, otherwise 0 is returned.
In the following example, the right 1 XOR 1 is evaluated first, and returns 0. Then, 1 XOR 0 is evaluated, and 1 is returned.
This page is licensed: GPLv2, originally from
SELECT NOT 10;
+--------+
| NOT 10 |
+--------+
| 0 |
+--------+
SELECT NOT 0;
+-------+
| NOT 0 |
+-------+
| 1 |
+-------+
SELECT NOT NULL;
+----------+
| NOT NULL |
+----------+
| NULL |
+----------+
SELECT ! (1+1);
+---------+
| ! (1+1) |
+---------+
| 0 |
+---------+
SELECT ! 1+1;
+-------+
| ! 1+1 |
+-------+
| 1 |
+-------+SELECT 1 XOR 1;
+---------+
| 1 XOR 1 |
+---------+
| 0 |
+---------+
SELECT 1 XOR 0;
+---------+
| 1 XOR 0 |
+---------+
| 1 |
+---------+
SELECT 1 XOR NULL;
+------------+
| 1 XOR NULL |
+------------+
| NULL |
+------------+SELECT 1 XOR 1 XOR 1;
+---------------+
| 1 XOR 1 XOR 1 |
+---------------+
| 1 |
+---------------+Logical OR. When both operands are non-NULL, the result is 1 if any operand is non-zero, and 0 otherwise. With a NULL operand, the result is 1 if the other operand is non-zero, and NULL otherwise. If both operands are NULL, the result is NULL.
For this operator, can be used.
Note that, if the PIPES_AS_CONCAT is set, || is used as a string concatenation operator. This means that a || b is the same as CONCAT(a,b). See for details.
In , || ignores .
In :
This page is licensed: GPLv2, originally from
OR, ||SELECT 1 || 1;
+--------+
| 1 || 1 |
+--------+
| 1 |
+--------+
SELECT 1 || 0;
+--------+
| 1 || 0 |
+--------+
| 1 |
+--------+
SELECT 0 || 0;
+--------+
| 0 || 0 |
+--------+
| 0 |
+--------+
SELECT 0 || NULL;
+-----------+
| 0 || NULL |
+-----------+
| NULL |
+-----------+
SELECT 1 || NULL;
+-----------+
| 1 || NULL |
+-----------+
| 1 |
+-----------+SELECT 0 || NULL;
+-----------+
| 0 || NULL |
+-----------+
| 0 |
+-----------+