Function Reference

MOD

Returns the remainder of dividing one number by another.

MySQL 8.4
MOD(dividend, divisor)
dividend
Dividend
DECIMAL
divisor
Divisor
DECIMAL

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.4
SELECT MOD(7, 3);
MOD(7, 3)
1

Remainder of a negative number

MySQL 8.4
SELECT MOD(-7, 3);
MOD(-7, 3)
-1

Table rows with an even id

MySQL 8.4
SELECT member_id,
	member_name
FROM FamilyMembers
WHERE MOD(member_id, 2) = 0;
member_idmember_name
2Flavia Quincey
4Lela Quincey
6Ernest Forrest
8Wednesday Addams

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.

See also