# MOD

## Syntax

```sql
MOD(N,M), N % M, N MOD M
```

## Description

Modulo operation. Returns the remainder of N divided by M. See also [Modulo Operator](https://mariadb.com/docs/server/reference/sql-structure/operators/arithmetic-operators/modulo-operator).

If the `ERROR_ON_DIVISION_BY_ZERO` [SQL\_MODE](https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode) is used, any number modulus zero produces an error. Otherwise, it returns `NULL`.

The integer part of a division can be obtained using [DIV](https://mariadb.com/docs/server/reference/sql-functions/numeric-functions/div).

## Examples

```sql
SELECT 1042 % 50;
+-----------+
| 1042 % 50 |
+-----------+
|        42 |
+-----------+

SELECT MOD(234, 10);
+--------------+
| MOD(234, 10) |
+--------------+
|            4 |
+--------------+

SELECT 253 % 7;
+---------+
| 253 % 7 |
+---------+
|       1 |
+---------+

SELECT MOD(29,9);
+-----------+
| MOD(29,9) |
+-----------+
|         2 |
+-----------+

SELECT 29 MOD 9;
+----------+
| 29 MOD 9 |
+----------+
|        2 |
+----------+
```

## See Also

* [Operator Precedence](https://mariadb.com/docs/server/reference/sql-structure/operators/operator-precedence)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}
