SQLite 3 reference · Math Functions

SQLite MOD() Function

Return the remainder of dividing one number by another. Unlike the % operator it also works with decimals.

SQLite 3 Since 3.35.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

mod(X, Y)

Parameters

ParameterDescription
X A number (text that looks like a number is converted).
Y The divisor.

Return value

The remainder, or NULL when Y is 0.

Examples

Remainders
SELECT mod(10, 3) AS a, mod(7.5, 2) AS b, 7.5 % 2 AS percent_op;

Output

a | b | percent_op
1 | 1.5 | 1

Run this on your computer — see “Get Started” for setup.

Even or odd
SELECT order_id, mod(order_id, 2) = 0 AS even
FROM orders
LIMIT 4;

Output

order_id | even
1 | 0
2 | 1
3 | 0
4 | 1

Run this on your computer — see “Get Started” for setup.

This is one of SQLite's built-in math functions, available since 3.35.0 when SQLite is compiled with SQLITE_ENABLE_MATH_FUNCTIONS (the default for the sqlite3 command-line tool and most language bindings). The in-browser SQLite on this site is built without them, so the examples show output from standard SQLite instead.

Version history

VersionChange
SQLite 3.35.0Added

In other languages

Was this page helpful?