← Back to MySQL Course | Chapter 8: Operators & Conditional Logic | Lesson 1 of 5

Arithmetic Operators

Arithmetic operators are your calculator buttons, letting MySQL add, subtract, multiply and divide numbers in a query.
Syntax
sql
SELECT column1 + column2, column1 - column2,
       column1 * column2, column1 / column2, column1 % column2
FROM table_name;

Addition Operator (+)

The addition operator joins two numbers to find their total sum, such as combining a base price and a shipping fee. It is a fundamental operator in SQL math and works the same way inside SELECT, WHERE, or UPDATE expressions.

Example: Addition Operator (+)

sql
SELECT base_price + shipping_fee AS total FROM orders;

Subtraction Operator (-)

The subtraction operator deducts one number from another. You can use it to find the difference between two values, such as calculating days between a due date and today's date once combined with date functions.

Example: Subtraction Operator (-)

sql
SELECT price - discount AS final_price FROM orders;

Multiplication Operator (*)

The multiplication operator multiplies two numbers together. This is useful for scaling values or calculating totals, like multiplying unit price by quantity to get a line-item subtotal.

Example: Multiplication Operator (*)

sql
SELECT unit_price * quantity AS total FROM order_items;

Division Operator (/)

The division operator divides the first number by the second. It always returns a float result in MySQL, even when dividing two integers evenly, so remember to round or cast if you need a whole number.

Example: Division Operator (/)

sql
SELECT 10 / 4 AS result; -- always returns a float, even for exact division

Modulo Operator (%)

The modulo operator returns the remainder of a division. It is helpful for finding odd or even numbers, or for tasks like distributing rows evenly across a fixed number of buckets.

Example: Modulo Operator (%)

sql
SELECT id, id % 2 AS remainder FROM users; -- 0 = even, 1 = odd
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Expecting / to return an integer, when 5 / 2 gives 2.5000 (use DIV for integer division).
  2. Doing arithmetic with a NULL column, so the whole result becomes NULL.
  3. Dividing by zero, which returns NULL (and gives a warning or an error in strict mode).
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.