MySQL MOD Function

MySQL MOD function is one of the SQL Mathematical Function, which is helpful to find the Modulus. Or say, MySQL MOD function 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;

This MOD function divides the X with Y value and retunes the reminder.

MySQL MOD Function Example 1

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

SELECT MOD(25, 5);

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

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

MySQL MOD Example 2

The MOD Mathematical Function also allows you to find 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 `MySQL Tutorial`.customer;
MySQL MOD Function 2