This tutorial explains how to use the MySQL MOD function with syntax and examples.
The MySQL MOD function returns the remainder of n divided by m.
The syntax for the MOD function in MySQL is:
MOD( n, m )
OR
n MOD m
OR
n % m
The value that will be divided by m.
The value that will be divided into n.
The MOD function can be used in the following versions of MySQL:
Let's look at some MySQL MOD function examples and explore how to use the MOD function in MySQL.
For example:
mysql> SELECT MOD(12, 5);
Output: 2
mysql> SELECT MOD(12, 0.18);
Output: 0.12
mysql> SELECT MOD(100, 3.5938);
Output: 2.9674
mysql> SELECT 12 MOD 5;
Output: 2
mysql> SELECT 12 MOD 0.18;
Output: 0.12
mysql> SELECT 100 MOD 3.5938;
Output: 2.9674
mysql> SELECT 12 % 5;
Output: 2
mysql> SELECT 12 % 0.18;
Output: 0.12
mysql> SELECT 100 % 3.5938;
Output: 2.9674