Skip to content
SQLSimplified
numeric

MOD()

Returns the remainder of a division (modulo).

Description

MOD returns the remainder after dividing one number by another (the modulo operation). It's the classic tool for "every Nth row", checking even/odd, or wrapping counters. MOD(10, 3) is 1.

Syntax

MOD(dividend, divisor)
dividend % divisor

Parameters

NameDescriptionOptional
dividendThe value to divide.No
divisorThe value to divide by.No

Return Type

Returns the same numeric type as the inputs.

Examples

Employees & Departments

Loading database engine...

Employees & Departments

Loading database engine...

Even or odd

MOD(id, 2) = 0 means even; = 1 means odd. Pair with WHERE to grab every other row.

Common Mistakes

  • Dividing by zero. MOD(x, 0) errors — guard the divisor.
  • Sign of the result. The sign follows the dividend; MOD(-17, 5) is -2 in most SQL engines.
  • Confusing with division. MOD gives the leftover, not the quotient.

See also: FLOOR, ABS.

Search

Search lessons, functions, examples, and practice problems