Operators

Operators can be used for comparing values or for assigning values. There are several operators and they may be used in different SQL statements and clauses. Some can be used somewhat on their own, not within an SQL statement clause.

For comparing valuesstring or numericyou can use symbols such as the equal-sign (i.e., =) or the exclamation point and the equal-sign together (i.e., !=). You might use these in WHERE clauses or within a flow-control statement or function (e.g., IF( )). You can also use basic regular expressions with the LIKE operator.

For assigning values, you can also use the equal-sign or other arithmetic symbols (e.g. plus-sign). You might do this with the SET statement or in a SET clause in an UPDATE statement.

Title Description

Arithmetic Operators

Title Description
Addition Operator (+) Addition.
DIV Integer division.
Division Operator (/) Division.
MOD Modulo operation. Remainder of N divided by M.
Modulo Operator (%) Modulo operator. Returns the remainder of N divided by M.
Multiplication Operator (*) Multiplication.
Subtraction Operator (-) Subtraction and unary minus.

Assignment Operators

Title Description
Assignment Operator (:=) Assignment operator for assigning a value.
Assignment Operator (=) The equal sign as an assignment operator.

Bit Functions and Operators

Title Description
Operator Precedence Precedence of SQL operators
& Bitwise AND
<< Left shift
>> Shift right
BIT_COUNT Returns the number of set bits
^ Bitwise XOR
| Bitwise OR
~ Bitwise NOT
Parentheses Parentheses modify the precedence of other operators in an expression
TRUE FALSE TRUE and FALSE evaluate to 1 and 0

Comparison Operators

Title Description
!= Not equal operator.
< Less than operator.
<= Less than or equal operator.
<=> NULL-safe equal operator.
= Equal operator.
> Greater than operator.
>= Greater than or equal operator.
BETWEEN AND True if expression between two values.
COALESCE Returns the first non-NULL parameter
GREATEST Returns the largest argument.
IN True if expression equals any of the values in the list
INTERVAL Index of the argument that is less than the first argument
IS Tests whether a boolean is TRUE, FALSE, or UNKNOWN.
IS NOT Tests whether a boolean value is not TRUE, FALSE, or UNKNOWN
IS NOT NULL Tests whether a value is not NULL
IS NULL Tests whether a value is NULL
ISNULL Checks if an expression is NULL
LEAST Returns the smallest argument.
NOT BETWEEN Same as NOT (expr BETWEEN min AND max)
NOT IN Same as NOT (expr IN (value,...))

Logical Operators

Title Description
! Logical NOT.
&& Logical AND.
XOR Logical XOR.
|| Logical OR.

Other Operators Articles

Title Description
Operator Precedence Precedence of SQL operators
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.

© 2021 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/operators/