The MySQL MOD function performs the modulo operation. If you recall, the modulo operation returns the remainder after division.

MySQL allows us the functionality of performing mathematical operations like the modulus function.

Whatever your reason for using the modulus function, the tutorial below explains how to use the MOD function with MySQL.

The MySQL MOD function has 3 main syntaxes which are shown below:

MOD(N, M) N % M N MOD M

These will return the remainder of N divided by M.

You can use any syntax you desire since they are functionally equivalent.

Here is an example of using the MOD function in MySQL:

SELECT MOD(64, 10); -- gives 4

This is example 2:

SELECT 31 MOD 2; -- gives 1

And here is the final example:

SELECT 8 % 3; -- gives 2

As you just saw, working with modulus arithmetic in MySQL is fairly straightforward. We hope this tutorial on the MySQL mod function was useful.

Link to this Page