MOD() in MySQL — How It Works

What the MySQL MOD() function does, with an example.

Published October 21, 2026

MOD(a, b) returns the remainder of a divided by b; the % operator is equivalent.

How it works

Common for even/odd checks and cyclic values.

Try it in MySQL

SELECT MOD(10, 3)
1
SELECT 10 % 3
1
SELECT * FROM t WHERE MOD(id, 2) = 0
even ids

Practical examples

Example 1

SELECT MOD(10, 3);
-- 1

Example 2

SELECT 10 % 3;
-- 1

Example 3

SELECT * FROM t WHERE MOD(id, 2) = 0;
-- even ids

Use it in a real query

SELECT id, MOD(10, 3) AS result
FROM your_table
LIMIT 10;

Common mistakes

  • Dividing by zero returns NULL.
  • Negative operands keep the sign of the dividend.
  • Using MOD on floats.

Key takeaways

  • MOD() in one line: MOD(a, b) returns the remainder of a divided by b; the % operator is equivalent.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

Even or odd?

MOD(n, 2) = 0 means even.

Does MOD() work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles