CodeBlanks Logo Icon CodeBlanks

MOD

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

query.sql
-- even ids
SELECT name
FROM products
WHERE

Sample solution

query.sql
SELECT name
FROM products
WHERE MOD(id, 2) = 0

Expected output

name
Kalem
Defter

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Remainder

Question
SELECT ____(10, 3);
Answer
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.

All lessons in Beginner