| Expression & Operators |
| |
| Logical Operators |
| |
| Logical operators, evaluate expressions to determine whether they are true (non-zero) or false (zero). It is also possible for a logical expression to evaluate to NULL if its value cannot be ascertained (for example, 1 AND NULL is of indeterminate value). |
| |
| MySQL allows the C-style &&, ||, and ! operators as alternative forms of AND, OR, and NOT. Note in particular the || operator; ANSI SQL specifies || as the string concatenation operator, but in MySQL it signifies a logical OR operation. If you want the ANSI behavior for ||, start the server with the --ansi or --sql-mode=PIPES_AS_CONCAT option. |
| |
| If you use the following expression, expecting it to perform string concatenation, you may be surprised to discover that it returns the number 0: |
| |
| 'abc' || 'def' |
| |
| 'abc' and 'def' are converted to integers for the operation, and both turn into 0. In MySQL, you must use CONCAT('abc','def') to perform string concatenation: |
| |
| CONCAT('abc','def') 'abcdef' |
| |
| Logical Operators |
Operator |
Syntax |
Meaning |
AND, && |
a AND b, a && b |
Logical intersection; true if both operands are true |
OR, || |
a OR b, a || b |
Logical union; true if either operand is true |
XOR |
a XOR b |
Logical exclusive-OR; true if exactly one operand is true |
NOT, ! |
NOT a, !a |
Logical negation; true if operand is false |
|
| |
| |
|
|
| |
| |