> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/sql-functions/numeric-functions/mod.md).

# MOD

Calculate modulo. This function returns the remainder of a number divided by another number.

## Syntax

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

## Description

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

Any number modulo zero returns `NULL`. When the [ERROR\_FOR\_DIVISION\_BY\_ZERO](/docs/server/server-management/variables-and-modes/sql_mode.md#error_for_division_by_zero) SQL mode is enabled, as it is by default, it also produces a warning. If [strict mode](/docs/server/server-management/variables-and-modes/sql_mode.md#strict_trans_tables) is also enabled, an `INSERT` or `UPDATE` that takes a modulo by zero fails with an error instead.

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

## 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 |
+----------+

SELECT MOD(0.5, 0.33);
+----------------+
| MOD(0.5, 0.33) |
+----------------+
|           0.17 |
+----------------+
```

## See Also

* [Operator Precedence](/docs/server/reference/sql-structure/operators/operator-precedence.md)

<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" %}
