What is MOD() in SQL?

The MOD() function returns the remainder of a dividend divided by a divisor. Figure 1 shows the mathematical representation of the MOD() function.

Figure 1: Mathematical representation of MOD() function

Syntax

MOD(dividend, divisor)

Parameter

The MOD() function requires two parameters:

  • A dividend can be any number.
  • A divisor can be any number except zero.

NOTE: A divisor should not be zero.

Return value

MOD() returns the remainder of a dividend divided by a divisor that is sent as a parameter.

NOTE: If a divisor is zero, then MOD() returns NULL.

Example

/*example showing how to use MOD(X)*/
-- positive number
select MOD(4,3);
-- negative number
select MOD(-6,3);
-- fractional number
select MOD(4.6,2.1);
-- zero divisor
select MOD(4,0)

Free Resources