Operators

SQL Arithmetic Operators

OperatorDescriptionExample
+AddPrice + 1
-SubtractPrice - 1
*MultiplyPrice * Stock
/DivideAmount / 2
%Modulo (remainder)OrderID % 2

Example

Find orders with an even OrderID and show the amount including 18% tax:

SELECT OrderID, Amount, ROUND(Amount * 1.18, 2) AS WithTax
FROM Orders
WHERE OrderID % 2 = 0;

Result: 4 rows

OrderIDAmountWithTax
10289.9106.08
10456.2566.38
106320.75378.48
108198.4234.11

Integer Division

When both operands are integers, many databases (SQL Server, PostgreSQL, SQLite) do integer division: 7 / 2 is 3. Multiply by 1.0 to get a decimal result. MySQL and Oracle return 3.5.

Example

Compare integer division with decimal division:

SELECT 7 / 2 AS IntegerDivision, 7 * 1.0 / 2 AS DecimalDivision;

Result: 1 row

IntegerDivisionDecimalDivision
33.5

Comparison and Logical Operators

TypeOperators
Comparison= <> != > < >= <=
LogicalAND OR NOT
SpecialBETWEEN IN LIKE IS NULL EXISTS ANY ALL

The following pages cover each of these in detail.