Operator |
Role |
Not OR! |
Logical Non- |
And OR && |
Logic and |
OR OR | | |
Logical OR |
Xor |
Logical XOR or |
1, logical non (not OR!) )
(1) When the operand is 0 o'clock, the resulting value is 1
(2) When the operand is not 0 o'clock, the resulting value is 0
(3) When the operand is null, the resulting value is null
Mysql> SELECT not ten,!10, not (1-1),! (1-1), not +, not NULL;
+--------+-----+-----------+--------+---------+----------+
| Not 10 |!10 | Not (1-1) |! (1-1) | Not | Not NULL |
+--------+-----+-----------+--------+---------+----------+
| 0 | 0 | 1 | 1 | 0 | NULL |
+--------+-----+-----------+--------+---------+----------+
2. Logic and (and or &&)
(1) When all operands are non-0 values and are not NULL, the resulting value is 1
(2) when one or more operands is 0 o'clock, the resulting value is 0
(3) The remainder of the value is NULL
Mysql> SELECT 1 AND-1, 1 && 0, 0 and NULL, 1 && null;
+----------+--------+------------+-----------+
| 1 AND-1 | 1 && 0 | 0 and NULL | 1 && NULL |
+----------+--------+------------+-----------+
| 1 | 0 | 0 | NULL |
+----------+--------+------------+-----------+
3. Logic or (or | |)
(1) When two operands are non-NULL values, and any one operand is not a 0 value, the result is 1, otherwise 0
(2) When one operand is null and the other operand is a non-0 value, the result is 1, otherwise the result is null
(3) When two operands are null, the resulting result is null
mysql> SELECT 1 OR-1 OR 0, 1 | | 2, 0 OR null, NULL | | NULL;
+--------------+--------+-----------+--------------+
| 1 OR-1 OR 0 | 1 | | 2 | 0 OR NULL | NULL | | NULL |
+--------------+--------+-----------+--------------+
| 1 | 1 | NULL | NULL |
+--------------+--------+-----------+--------------+
4. Logical XOR (XOR)
(1) The calculation of a XOR B is equivalent to (A and (not B)) or ((not a) and b)
(2) When either operand is null, the return value is null
(3) for non-NULL operands, if two operands are non-0 values or 0 values, the result is 0
(4) If one is a value of 0 and the other is a non-0 value, the return result is 1
Mysql> SELECT 1 xor 1, 0 xor 0, 1 XOR 0, 1 xor NULL, 1 xor 1 XOR 1;
+---------+---------+---------+------------+---------------+
| 1 XOR 1 | 0 XOR 0 | 1 XOR 0 | 1 XOR NULL | 1 XOR 1 XOR 1 |
+---------+---------+---------+------------+---------------+
| 0 | 0 | 1 | NULL | 1 |
+---------+---------+---------+------------+---------------+
MySQL logical operator