MySQL Mod Function

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.

MySQL MOD Syntax

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

N % M

These will return the remainder of N divided by M.

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

MySQL MOD Example

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

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...