MySQL MOD() Function

In MySQL, the MOD() function returns the remainder of one number divided by another.

MOD() Syntax

Here is the syntax of MySQL MOD() function:

MOD(number1, number2)
number1 MOD number2
number1 % number2

Parameters

number1
Required. A value that will be divided.
number2
Required. The divisor.

Return value

In MySQL, the MOD() function returns the remainder of one number divided by another.

  • If number2 equals 0, the function will return NULL.
  • If any parameter is NULL, the function will return NULL.

MOD() Examples

SELECT
    MOD(100, 7),
    MOD(100, 10),
    100 MOD 7,
    100 MOD 10,
    100 % 7,
    100 % 10,
    MOD(0, 1),
    MOD(1, 0),
    MOD(NULL, 1)\G

output

*************************** 1\. row ***************************
 MOD(100, 7): 2
MOD(100, 10): 0
   100 MOD 7: 2
  100 MOD 10: 0
     100 % 7: 2
    100 % 10: 0
   MOD(0, 1): 0
   MOD(1, 0): NULL
MOD(NULL, 1): NULL