MOD
- SQL course
- Beginner
- Lesson 51/115
- 4 min
Get the remainder of division with MOD.
MOD
MOD(x, y) returns the remainder of x divided by y. The % operator does the same.
SELECT MOD(10, 3) AS kalan;The remainder of 10 divided by 3 is 1.
The expression MOD(10, 3) AS kalan is evaluated and returned.
MOD — details
To check even or odd use MOD(n, 2) = 0 for even. Modulus is used in cyclic grouping operations.
Practice MOD
Select from products those whose id is even (using MOD).
Starter code
-- even ids
SELECT name
FROM products
WHERESample solution
SELECT name
FROM products
WHERE MOD(id, 2) = 0Expected output
name Kalem Defter
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Remainder
SELECT ____(10, 3);
SELECT MOD(10, 3);
Explanation: MOD(10, 3) returns the remainder of the division: 1.
2 MOD: match the terms
| Term | Meaning |
|---|---|
MOD |
remainder |
POWER |
power |
SQRT |
square root |
ABS |
absolute |
3 What is MOD(10, 3)?
- 0
- 1 Correct answer
- 3
- 10
Explanation: 10 = 3*3 + 1, remainder 1.