MOD
Returns the remainder of dividing one number by another.
MySQL 8.1
MOD(dividend, divisor)Parameters
- dividendDECIMAL
- Dividend
- divisorDECIMAL
- Divisor
Return value
The remainder with the sign of the dividend: MOD(-7, 3) = -1; NULL when dividing by 0
Examples
Remainder of a division
MySQL 8.1
SELECT MOD(7, 3);Remainder of a negative number
MySQL 8.1
SELECT MOD(-7, 3);Table rows with an even id
MySQL 8.1
SELECT member_id,
member_name
FROM FamilyMembers
WHERE MOD(member_id, 2) = 0;Details
Instead of the function, you can use the % and MOD operators: 7 % 3 and 7 MOD 3 also give 1. The function works with fractional numbers too: MOD(7.5, 2) returns 1.5.