MOD( )

This MySQL function returns the remainder of a number given in the first argument when divided by the number given in the second argument, the modulo.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

MOD(number, number)
number MOD number

Explanation

This function returns the remainder of a number given in the first argument when divided by the number given in the second argument, the modulo. The function works the same as using the % operator between two given numbers. The second syntax shown is available as of Version 4.1 of MySQL. Starting with Version 4.1.7, fractional values may be given.

Examples

SELECT MOD(10, 3);

+------------+
| MOD(10, 3) |
+------------+
|          1 |
+------------+

Here's an example of the alternate syntax:

SELECT 10 MOD 3;

+----------+
| 10 MOD 3 |
+----------+
|        1 |
+----------+