Combining Conditions: AND, OR, IN & LIKE
Combine several filters in one WHERE clause to find exactly the rows a business question needs.
Why this matters
Real questions have several conditions at once, like big orders from two cities. Combining filters lets you answer them in one query.
AND Narrows, OR Widens
AND keeps rows that meet every condition. OR keeps rows that meet at least one. When you mix them, use brackets so your meaning is clear.
In real life: "Show me buses to Abuja AND under ₦90,000" gives fewer results. "Show me buses to Abuja OR Kano" gives more. AND narrows. OR widens.
IN Replaces Many ORs
region IN ('Lagos', 'Abuja') is a shorter way to write region = 'Lagos' OR region = 'Abuja'.
In real life: Asking "is the city Lagos, Abuja, or Kano?" is easier than three separate questions. IN lets you ask all of them at once.
SELECT order_id, region, amount
FROM orders
WHERE status = 'COMPLETED'
AND region IN ('Lagos', 'Abuja');
LIKE for Patterns, BETWEEN for Ranges
LIKE 'A%' finds text starting with A (% means any characters). BETWEEN 100 AND 500 includes both 100 and 500.
In real life: LIKE is like searching your contacts for "Ade": it finds Adeola and Adebayo. BETWEEN is like "prices from 100 to 500", with both ends included.
Your practice task
The regional sales manager wants to review big wins in the two biggest markets. List order_id, region, and amount for COMPLETED orders from Lagos or Abuja where the amount is at least 10,000.
How to do it
- List every condition the manager gave: status, cities, and size.
- Decide which conditions must all be true together.
- Check if the two cities can be written as one short list.
- Add the filters, then press Run proof.
Practice it for free in the app. You get instant checks that show what you got right and what to fix. A lesson takes about two minutes and you can try as many times as you like.
Quick reference: Combining Filters
AND = all conditions, OR = any condition, IN = any value in a list, LIKE = text pattern, BETWEEN = inclusive range.
WHERE status = 'COMPLETED'
AND region IN ('Lagos', 'Abuja')
AND amount BETWEEN 100 AND 5000
AND customer_name LIKE 'A%'More lessons in this course
- Unique Values & AveragesUse DISTINCT, AVG, MIN, and MAX to describe a dataset in a single summary row.
- SQL COALESCE Example: Sum Totals With NULL ValuesLearn how SELECT, FROM, WHERE, and COALESCE prevent blank values from ruining database calculations.
- Filtering Only What MattersPick exactly the rows you want—so surprise categories don't sneak in.