WHERE Clause — Complete Guide
WHERE Clause — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 12 of 100
WHERE Clause
Basics → Advanced
Basics · 1 — SQL · ~6 min · MySQL — Queries & Clauses
What is this?
WHERE filters rows before they appear in the result. You compare columns to literals or parameters with =, <>, IN, BETWEEN, LIKE, and IS NULL.
Why should you care?
Flipkart’s “orders from last 7 days” is a WHERE on placed_at — without it you scan millions of historical rows.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
SELECT order_id, order_ref, total_inr
FROM orders
WHERE total_inr >= 500
AND order_ref LIKE 'DF-%';
What happened?
- Both conditions must be true (AND).
- >= keeps high-value carts.
- LIKE 'DF-%' matches refs starting with DF-.
- Rows failing either test are dropped.
Practice next
- Insert orders with mixed totals and refs.
- Run the query; tweak the 500 threshold.
- Replace LIKE with IN ('DF-1001','DF-1002').
- Add OR total_inr BETWEEN 100 AND 200 for mid-range orders.
- Filter WHERE customer_id IN (SELECT customer_id FROM customers WHERE city='Pune');
Remember
WHERE runs row filters early. Combine tests with AND / OR — use parentheses. IS NULL is the correct null check.
Swiggy high-value refund queue
Ops filters orders above ₹500 for manual review during fraud spikes.
Outcome: Small WHERE clause saves hours of scrolling.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!