In MySQL, DIV is a binary operator—not a function—that performs integer division between two numbers. You write a DIV b, and MySQL discards any fractional remainder toward zero.
Unlike the regular / operator, which returns a DECIMAL or DOUBLE with fractional digits, DIV always produces a whole integer. It pairs naturally with MOD when splitting totals into full groups and remainders.
dividend DIV divisor
dividend: Left-hand numeric expression.divisor: Right-hand numeric expression. Do NOT write DIV(a, b) with parentheses.Suppose demo_orders tracks item quantities ordered, and your warehouse packs 12 units per full carton. Using DIV alongside MOD shows both full cartons and loose items in one query.
SELECT
order_id,
quantity,
quantity DIV 12 AS full_cartons,
quantity MOD 12 AS loose_items
FROM demo_orders
WHERE order_id BETWEEN 601 AND 604;
| order_id | quantity | full_cartons | loose_items |
|---|---|---|---|
| 601 | 29 | 2 | 5 |
| 602 | 24 | 2 | 0 |
| 603 | 7 | 0 | 7 |
| 604 | NULL | NULL | NULL |
Order 601 has 29 units: 29 DIV 12 gives 2 full cartons, and 29 MOD 12 leaves 5 loose units.
SELECT DIV(10, 3) causes a MySQL syntax error. Always place DIV between the two operands: SELECT 10 DIV 3.10 DIV 0 returns NULL in permissive SQL modes. However, if ERROR_FOR_DIVISION_BY_ZERO is active during INSERT or UPDATE in strict mode, MySQL raises an error. Guard variable divisors with NULLIF(divisor, 0).DIV truncates toward zero, not negative infinity. For example, -7 DIV 2 returns -3, whereas FLOOR(-7 / 2) returns -4.NULL, DIV evaluates to NULL.The / operator performs exact decimal or floating-point division (7 / 2 returns 3.5000), while DIV discards the fraction and returns an integer (7 DIV 2 returns 3).
Yes. MySQL converts operands to DECIMAL before dividing and drops the fractional result. For instance, 10.8 DIV 2.5 returns 4.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.