Expressions and precedence
Core idea
An expression computes a value from literals, columns or operators. Multiplication normally binds more tightly than addition. Parentheses make the intended grouping explicit. A computed SELECT expression does not modify the stored price.
Minimal example
SELECT 2 + 3 * 4, (2 + 3) * 4;Expected rows (in order):
14 | 20How it works
The first expression multiplies before adding; the second adds first. Use parentheses to communicate business rules, not to guess an engine’s evaluation order. SQL engines can differ in integer division, implicit conversions and some operators. These integer addition and multiplication examples avoid those differences.
Practical example
SELECT id, price_cents * 2 + 50 FROM products ORDER BY id;Expected rows (in order):
1 | 7502 | 3503 | 48504 | 250Practice
Calculate the price of three units plus a fixed 25-cent charge for each product. Compare against multiplying the sum of price and charge by three.