MariaDB MOD Operator

In MariaDB, MOD is a built-in operator that returns the remainder when one number is divided by another.

MariaDB MOD Syntax

Here is the syntax of the the MariaDB MOD operator:

number1 MOD number2
number1 % number2

You can also use the MOD(number1, number2) function.

Parameters

number1

Optional. The dividend.

number2

Optional. The divisor.

Return value

The MariaDB MOD operator returns the remainder of dividing one number by another.

If number2 equals 0, the MOD function will return NULL.

If the number1 argument is NULL, the MOD function will return NULL.

MariaDB MOD Examples

The following statement shows the basic usage of the MariaDB DIV operator:

SELECT
  3 MOD 2,
  4 MOD 2,
  5 MOD 2,
  6 MOD 2,
  7 MOD 2;

Output:

+---------+---------+---------+---------+---------+
| 3 MOD 2 | 4 MOD 2 | 5 MOD 2 | 6 MOD 2 | 7 MOD 2 |
+---------+---------+---------+---------+---------+
|       1 |       0 |       1 |       0 |       1 |
+---------+---------+---------+---------+---------+

You can use the % operator to achieve that:

SELECT
  3 % 2,
  4 % 2,
  5 % 2,
  6 % 2,
  7 % 2;

Output:

+-------+-------+-------+-------+-------+
| 3 % 2 | 4 % 2 | 5 % 2 | 6 % 2 | 7 % 2 |
+-------+-------+-------+-------+-------+
|     1 |     0 |     1 |     0 |     1 |
+-------+-------+-------+-------+-------+

Alternatively, you can use the MOD() function to do this:

SELECT
  MOD(3, 2),
  MOD(4, 2),
  MOD(5, 2),
  MOD(6, 2),
  MOD(7, 2);

Output:

+-----------+-----------+-----------+-----------+-----------+
| MOD(3, 2) | MOD(4, 2) | MOD(5, 2) | MOD(6, 2) | MOD(7, 2) |
+-----------+-----------+-----------+-----------+-----------+
|         1 |         0 |         1 |         0 |         1 |
+-----------+-----------+-----------+-----------+-----------+

Conclusion

In MariaDB, MOD is a built-in operator that returns the remainder when one number is divided by another.