MySQL MOD Function

MySQL MOD function is one of the Mathematical methods which is helpful in finding the Modulus. Or say it finds the remainder of different values. The syntax of the MOD function is as shown below:

SELECT MOD(X, Y);

SELECT X % Y;

SELECT X MOD Y;

It divides the X with the Y value and returns the remainder.

MySQL MOD Function Example

The MOD function returns the remainder or Modulus of the given value. The following query shows multiple ways to use this.

SELECT MOD(25, 5);

SELECT MOD(25, 4), MOD(29, 9);

SELECT 29 MOD 9, 28 MOD 5, 29 % 5;
MOD Function Example 1

This Mathematical method also allows you to find the Modulus of column data. In this MySQL example, we are going to find the Modulus of the Yearly Income column divided by 9.

SELECT EmpID, 
       FirstName,
       LastName,
       Occupation,
       YearlyIncome,
       MOD(YearlyIncome, 9) AS Mod9Income,
       Sales,
       Sales MOD 5 AS Mod5Sales
 FROM customer;
MySQL MOD Function Example 2