SQL Operators
On this page
SQL Operators
SQL operators are used to perform comparisons, logical operations, and calculations in queries.
Comparison Operators
- = Equal
- <> or != Not equal
- > Greater than
- < Less than
- >= Greater than or equal
- <= Less than or equal
SELECT name FROM customers WHERE country = 'USA';
Logical Operators
- AND
- OR
- NOT
SELECT name FROM customers WHERE country = 'USA' AND status = 'active';
Arithmetic Operators
- + Addition
- - Subtraction
- * Multiplication
- / Division
- % Modulus (database-specific)
SELECT price, quantity, price * quantity AS total FROM order_items;
Special Operators
- IN
- BETWEEN
- LIKE
- IS NULL
- EXISTS
SELECT name
FROM customers
WHERE country IN ('USA', 'Canada');
Bitwise Operators (Database-Specific)
Some database systems support bitwise operators such as &, |, ^. Support depends on the database engine.
Operator Precedence
SQL follows a logical order of precedence. For example, AND is evaluated before OR. Use parentheses to control evaluation order.
SELECT name FROM customers WHERE country = 'USA' AND (status = 'active' OR status = 'trial');
Common Mistakes
- Forgetting parentheses when mixing AND and OR
- Using = NULL instead of IS NULL
- Assuming operator precedence incorrectly
Next Step
You have completed the core SQL Tutorial. Continue with the SQL Database section to learn how to create and manage databases and tables.