Mod Function In Sql in SQL
? MOD() Function in SQL
The MOD() function returns the remainder of a division between two numbers (also called the modulus operation).
? Syntax:
MOD(dividend, divisor)dividend: The number to be divided.divisor: The number by which you divide.
? Example:
SELECT MOD(17, 5) AS remainder;Result:
| remainder |
|---|
| 2 |
Because 17 divided by 5 is 3 with a remainder of 2.
? Notes:
Equivalent function in some databases:
MOD()— MySQL, Oracle, PostgreSQL%operator — SQL Server (SELECT 17 % 5)
Useful for checking even/odd numbers (
MOD(number, 2)).
Let me know if you want examples with MOD() in different SQL dialects!