Last time you learned pattern matching with LIKE. But what if you need multiple conditions? Like finding customers in California who spent over $100?
Single WHERE conditions aren't enough. You need to combine multiple criteria logically.
Engagement Message
When have you needed to filter data with multiple requirements at once?
The AND operator lets you require ALL conditions to be true. Think of it as "this AND that AND the other thing."
SELECT * FROM customers WHERE state = 'CA' AND total_spent > 100;
This only returns California customers who spent over $100.
Engagement Message
What would happen if a customer spent $150 but lived in Texas?
The OR operator finds rows where ANY condition is true. It's like saying "this OR that."
SELECT * FROM products WHERE category = 'Electronics' OR price < 50;
This returns electronics products AND cheap products (under $50).
Engagement Message
Would a $200 electronics item be included in these results?
The NOT operator excludes rows that match a condition. It flips true to false.
SELECT * FROM orders WHERE NOT status = 'Cancelled';
This shows all orders except cancelled ones. Same as WHERE status <> 'Cancelled'.
Engagement Message
When would NOT be clearer than using <>?
Comparison operators let you compare values: > (greater), < (less), >= (greater or equal), <= (less or equal), <> (not equal).
SELECT * FROM inventory WHERE quantity <= 5 AND reorder_level >= 10;
