MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB - Operators



Operators are used to perform operation on two operands. Operators in MariaDB can be categorized as follows:

  • Arithmetic operators
  • Comparison operators
  • Logical operators

MariaDB Arithmetic operators

Arithmetic operators are used to perform arithmetic operations on two operands.

OperatorNameDescriptionExample
+AdditionAdd two valuesMore Info
-SubtractionSubtract one value from anotherMore Info
*MultiplicationMultiply two valuesMore Info
/DivisionDivide one value by anotherMore Info
%ModuloReturns remainder of division operationMore Info

MariaDB Comparison operators

Comparison operators are used to compare values of two operands. It returns true when values matches and false when values does not match.

OperatorDescriptionExample
=Equal toMore Info
!=Not equal toMore Info
<>Not equal toMore Info
>Greater thanMore Info
<Less thanMore Info
>=Greater than or equal toMore Info
<=Less than or equal toMore Info

MariaDB Logical operators

Logical operators are used to create and combine one or more conditions.

Operator Description
ALL Returns true if all of the subquery values meet the condition.
AND Only includes rows where both conditions is true.
ANY Returns true if any of the subquery values meet the condition.
BETWEEN Selects values within a given range.
EXISTS Tests for the existence of records from a subquery.
IN Allows you to specify multiple values in a WHERE clause.
LIKE Searches for a specified pattern in a column.
NOT Only includes rows where a condition is not true.
NOT LIKE Negation of LIKE.
OR Returns True when any of the conditions is true.
IS NULL Tests for null values.
IS NOT NULL Tests for non-null values.
SOME Returns true if any of the subquery values meet the condition.

MariaDB Operators Precedence

Operator precedence (order of operations) is a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given expression.

For example, multiplication has higher precedence than addition. Thus, the expression 1 + 2 × 3 is interpreted to have the value 1 + (2 × 3) = 7, and not (1 + 2) × 3 = 9. When exponent is used in the expression, it has precedence over both addition and multiplication. Thus 3 + 52 = 28 and 3 × 52 = 75.

The following table lists the precedence of MariaDB operators. Operators are listed top to bottom, in descending precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence.

PrecedenceOperators
18INTERVAL
17BINARY, COLLATE
16!
15- (Unary minus), [[bitwise-not|]] (Unary bit inversion)
14|| (String concatenation)
13^
12*, /, DIV, %, MOD
11-, +
10<<, >>
9&
8|
7= (Comparison), <=>, >=, >, <=, >, <>, !=, IS, LIKE, REGEXP, IN
6BETWEEN, CASE, WHEN, THEN, ELSE, END
5NOT
4AND, && (Logical and)
3XOR
2OR, || (Logical or)
1= (Assignment), :=