Operators¶
This page covers expression operators and commonly used control-flow and conversion functions. Precedence follows common SQL conventions: arithmetic precedes comparison, and comparison precedes logical operations. Use parentheses when in doubt.
Arithmetic¶
Operator |
Meaning |
|---|---|
|
Addition, subtraction, multiplication, and division |
|
Integer division |
|
Remainder |
Unary |
Negation |
Comparison¶
Operator |
Meaning |
|---|---|
|
Equality and inequality comparisons |
|
Range test |
|
Set membership |
|
Boolean comparison |
|
NULL test |
|
Pattern matching. Case sensitivity follows engine configuration. |
|
Case-insensitive pattern matching |
|
Returns the first non-NULL argument |
Comparing NULL with any value by using = never produces TRUE. Use IS NULL to test for NULL.
Logical¶
Operator |
Meaning |
|---|---|
|
AND |
|
OR |
|
Exclusive OR |
|
NOT |
Bitwise¶
Operator |
Meaning |
|---|---|
|
Bitwise AND / OR / XOR |
|
Left / right shift |
|
Bitwise NOT |
Assignment¶
Operator |
Meaning |
|---|---|
|
Assignment in contexts such as |
Type conversion¶
Function / operator |
Meaning |
|---|---|
|
Explicit conversion |
|
Explicit conversion, commonly used for date-time and decimal values |
|
Converts to binary-string semantics |
|
Encoding and serialization operations, subject to version support |
Control flow¶
Form |
Meaning |
|---|---|
|
Multiple branches |
|
Selects one of two values based on a condition |
|
Returns b when a is NULL |
|
Returns NULL when a equals b; otherwise returns a |
INTERVAL¶
Date operations use INTERVAL to express a time interval, together with DATE_ADD / DATE_SUB or literal operations. Units include the common set of DAY, HOUR, MINUTE, SECOND, MONTH, and YEAR.
SELECT DATE_ADD(NOW(), INTERVAL 1 DAY);