Logical XOR (XOR) : XOR « Logic Operator « MySQL Tutorial






'a XOR b' is mathematically equal to (a AND (NOT b)) OR ((NOT a) and b).

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.

mysql>
mysql> SELECT 1 XOR 1;
+---------+
| 1 XOR 1 |
+---------+
|       0 |
+---------+
1 row in set (0.00 sec)

mysql> SELECT 1 XOR 0;
+---------+
| 1 XOR 0 |
+---------+
|       1 |
+---------+
1 row in set (0.00 sec)

mysql> SELECT 0 XOR 0;
+---------+
| 0 XOR 0 |
+---------+
|       0 |
+---------+
1 row in set (0.00 sec)

mysql> SELECT 1 XOR 1 XOR 1;
+---------------+
| 1 XOR 1 XOR 1 |
+---------------+
|             1 |
+---------------+
1 row in set (0.00 sec)








8.5.XOR
8.5.1.Logical XOR (XOR)
8.5.2.Using Logical XOR operator with NULL value
8.5.3.Using XOR to link two conditions