Operators in MySQL
1. Arithmetic operators
Operator |
Description |
+ |
addition |
- |
Subtraction |
* |
multiplication |
/,DIV |
Division, return quotient |
%,MOD |
Division, return remainder |
mysql> select 0.1+0.3333,1.0-0.3333,0.1*0.3333,1/2,1%2,1/0,100%0,MOD(3,2);
+
| 0.1+0.3333 | 1.0-0.3333 | 0.1*0.3333 | 1/2 | 1%2 | 1/0 | 100%0 | MOD(3,2) |
+
| 0.4333 | 0.6667 | 0.03333 | 0.5000 | 1 | NULL | NULL | 1 |
+
1 row in set, 2 warnings (0.00 sec)
The divisor is 0 and returns NULL; the MOD() function has the same effect as the remainder of the operator %.
2. Comparison operators
Comparison operator |
Description |
= |
equal |
<> or != |
not equal to |
<=> |
NULL safe equals |
<= |
Less than or equal to |
< |
Less than |
> |
more than the |
>= |
greater or equal to |
BETWEEN |
Exists in the specified range |
IN |
Exists in the specified collection |
IS NULL |
Is NULL |
IS NOT NULL |
Not NULL |
LIKE |
Wildcard matching |
REGEXP or RLIKE |
Regular expression matching |
3. Logical operators
Logical Operators |
Description |
NOT or! |
Logical negation |
AND 或 && |
Logical and |
OR 或 || |
Logical OR |
XOR |
Logical exclusive OR |
4. Bitwise operator
Bit operator |
Description |
& |
Bit and |
| |
Bit or |
^ |
Bit XOR |
~ |
Bit inversion |
>> |
Bit shift right |
<< |
Bit shift left |