MySQL MOD Function

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

SELECT MOD(X, Y);

SELECT X % Y;

SELECT X MOD Y;

It divides the X with Y value and retunes the reminder.

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;
MySQL MOD Function 1

This Mathematical method also allows you to find the Modulus of a column data. In this MySQL example, we are going to find the Modulus of 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 2