🔀 SQL OR Operator – Select Rows Matching Any Condition
Need to retrieve data based on multiple possible values?
Use the SQLORoperator to return rows where at least one condition is true.
Whether you’re building dashboards, filtering reports, or querying user data—SQL OR gives your queries flexibility.
📌 What is SQL OR?
The SQL OR operator allows you to combine two or more conditions in a WHERE clause.
🔎 It returns rows if at least one condition is true.
🧾 SQL OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2;
✅ If either condition1 or condition2 is true → the row is included.
✅ Example: Get Customers from Multiple Cities
SELECT customer_name, city
FROM customers
WHERE city = 'Mumbai'
OR city = 'Bangalore';
🎯 This query returns customers who are either from Mumbai or Bangalore.
💡 Example: Products Priced Low or High
SELECT product_name, price
FROM products
WHERE price < 100
OR price > 5000;
Returns products that are either very cheap or very expensive.
🧠 Combine OR with AND (Use Parentheses!)
When mixing AND and OR, use parentheses () to control logic.
-- Find employees in HR or IT who earn above 50,000
SELECT first_name, department, salary
FROM employees
WHERE (department = 'HR' OR department = 'IT')
AND salary > 50000;
⚠️ Without parentheses, SQL may evaluate conditions in the wrong order.
🔄 Use OR with Pattern Matching
SELECT email
FROM users
WHERE email LIKE '%.edu'
OR email LIKE '%.org';
Filters users whose emails are from .edu or .org domains.
🧪 Practice Challenge
Question: Fetch orders that were either delivered late OR belong to VIP customers.
SELECT order_id, customer_type, delivery_status
FROM orders
WHERE delivery_status = 'Late'
OR customer_type = 'VIP';
📝 Final Thoughts
The OR operator is essential for:
✅ Writing flexible queries
✅ Filtering based on multiple criteria
✅ Making your SQL logic smarter and closer to business needs
Use it wisely with AND, NOT, and parentheses to get exactly the data you want.
Need a tutorial for:
- 🧮 SQL
BETWEEN,IN, orLIKE - 🔗 SQL
JOINwith filter logic - 📊 Power BI filters using SQL
OR

