AND, OR, NOT
Combine multiple conditions in WHERE
✅ What You Will Learn
Real queries rarely filter on just one condition. AND, OR, and NOT let you combine multiple conditions in the WHERE clause to express complex filters.
AND requires all conditions to be true for a row to be included. OR requires at least one condition to be true. NOT reverses a condition — it includes rows where the condition is false.
Understanding how these combine is essential for writing queries that answer real business questions.
📋 The orders table used in examples
| order_id | customer_name | product | amount | city |
|---|---|---|---|---|
| 1001 | Rahul Sharma | Laptop | 45000 | Delhi |
| 1002 | Priya Verma | Mobile Phone | 18000 | Noida |
| 1003 | Amit Kumar | Headphones | 3500 | Gurgaon |
| 1004 | Sneha Kapoor | Laptop | 52000 | Delhi |
| 1005 | Vikram Singh | Tablet | 28000 | Noida |
Syntax
Examples
📌 Key Points to Remember
- ✓AND is stricter — both conditions must be true
- ✓OR is looser — either condition being true is enough
- ✓Use brackets when mixing AND and OR to control evaluation order
- ✓IN() is a cleaner way to write multiple OR conditions on one column
- ✓NOT IN() excludes a list of values
🏢 Real-World Application
Combining conditions is where SQL becomes truly powerful. A CRM analyst at a telecom company might query: customers who are from Delhi AND have been inactive for more than 60 days AND have a premium plan — that is three AND conditions in one WHERE clause. A marketing analyst might look for customers from Mumbai OR Pune OR Bangalore for a regional campaign — three OR conditions. The IN() operator is particularly useful: WHERE state IN ('Delhi', 'UP', 'Haryana', 'Rajasthan') instead of four OR conditions. These patterns are used constantly in real business reporting.
⚠️ Common Mistakes to Avoid
❓ Frequently Asked Questions
What is the difference between AND and OR in SQL?
AND requires all conditions to be true for a row to be included. OR requires at least one condition to be true. AND is stricter and returns fewer rows; OR is looser and returns more rows.
What does IN do in SQL?
IN checks if a column value matches any value in a given list. WHERE product IN ('Laptop', 'Mobile', 'Tablet') is equivalent to WHERE product = 'Laptop' OR product = 'Mobile' OR product = 'Tablet' — just cleaner.
What does NOT IN do in SQL?
NOT IN excludes rows where the column value matches any value in the list. WHERE product NOT IN ('Laptop', 'Mobile') returns all rows except Laptop and Mobile orders.
Why do I need brackets when combining AND and OR?
AND is evaluated before OR (higher operator precedence), which can produce unexpected results. Brackets override this and make your intended logic explicit. Always use brackets when mixing AND and OR.
What is BETWEEN in SQL and how does it work?
BETWEEN is a shorthand for a range condition. WHERE amount BETWEEN 10000 AND 50000 is equivalent to WHERE amount >= 10000 AND amount <= 50000. Both endpoints are inclusive.
✏️ Practice Exercise
Write a query to find all orders where the product is either Laptop or Headphones, AND the amount is greater than ₹10,000.
Learn SQL with Live Trainer Guidance
These tutorials give you the theory. Our live SQL course at EVIKA Academy, Noida teaches you to apply SQL on real company datasets — with a trainer who uses it daily at MakeMyTrip.