SQL Or
SQL OR Operator
The OR operator is used in a WHERE clause to combine multiple conditions. A record is returned if at least one condition is true.
Basic Syntax
SELECT column1, column2 FROM table_name WHERE condition1 OR condition2;
Example: Match One of Two Countries
Return customers from either the USA or Canada:
SELECT name, country FROM customers WHERE country = 'USA' OR country = 'Canada';
Example: Numeric Conditions
Return products that are either expensive or low in stock:
SELECT name, price, stock FROM products WHERE price > 500 OR stock < 5;
OR with Multiple Conditions
You can combine more than two conditions with OR:
SELECT name, country FROM customers WHERE country = 'USA' OR country = 'Canada' OR country = 'UK';
OR vs AND
AND requires all conditions to be true. OR requires only one condition to be true. This difference can dramatically change your results.
Using Parentheses with AND and OR
When combining OR with AND, always use parentheses to control the logic.
Example: customers in the USA who are either active or trial:
SELECT name, country, status FROM customers WHERE country = 'USA' AND (status = 'active' OR status = 'trial');
Without parentheses, SQL may evaluate AND before OR, producing unexpected results.
Alternative: Using IN
When checking a column against multiple values, IN is often cleaner than multiple OR conditions:
SELECT name, country
FROM customers
WHERE country IN ('USA', 'Canada', 'UK');
Common Mistakes
- Forgetting parentheses when mixing AND and OR
- Using too many OR conditions instead of IN
- Creating overly broad conditions that return too many rows
Next Step
Continue with SQL NOT to learn how to exclude records from your results.