SQL MOD()
Published Oct 24, 2025
Contribute to Docs
The SQL math function MOD() returns the remainder after dividing one number by another. This is commonly used to determine if a number is even or odd, or to cycle through values.
Note: The behavior of
MOD()may vary slightly between SQL dialects. For example, some databases use%as an alternative operator.
Syntax
MOD(dividend, divisor)
Parameters:
dividend: The number to be divided.divisor: The number by which to divide.
Return value:
Returns the remainder obtained after dividing dividend by divisor.
Example 1
This example uses the MOD() function to find the remainder of 10 divided by 3:
SELECT MOD(10, 3);
The output of this code is:
1
Example 2
Given a table numbers:
| id | value |
|---|---|
| 1 | 7 |
| 2 | 12 |
| 3 | 15 |
This query uses MOD() to check which values are even:
SELECT id, value, MOD(value, 2) AS remainder FROM numbers;
The output will be:
| id | value | remainder ||----|-------|-----------|| 1 | 7 | 1 || 2 | 12 | 0 || 3 | 15 | 1 |
Here, a remainder of 0 indicates an even number.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 Courses
- With Certificate
- Beginner Friendly.17 hours
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.5 hours