WHERE
WHERE decides which rows make it into your result. Mastering it is the key to answering real questions with SQL.
On this page · 5 min · Beginner
On this page
- In simple words
- Learning objectives
- Explanation
- Syntax
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 27, 2026
In simple words#
WHERE is the filter on the clerk’s search: “…only students from Class 10 whose fees are pending.” Rows that don’t match are left out.
- WHERE
- Filter rows by a condition.
- AND / OR
- Combine conditions.
- LIKE / IN / BETWEEN
- Pattern, list and range filters.
Learning objectives#
- Filter with comparison operators
- Combine conditions with AND, OR and parentheses
- Use IN, BETWEEN and LIKE
- Test for NULL correctly
Explanation#
WHERE keeps rows for which the condition is true. Operators include =, <> (not equal), <, >, <= and >=.
IN (a, b, c) matches any value in a list; BETWEEN x AND y is inclusive at both ends; LIKE matches patterns where % means “any characters” and _ means “one character”.
NULL means “unknown”. Comparisons with NULL are never true, so use IS NULL and IS NOT NULL.
AND binds tighter than OR, so use parentheses when mixing them.
Syntax#
SELECT ... FROM ... WHERE condition1 AND (condition2 OR condition3);
Code example: Mid-priced furniture and stationery#
SELECT Name, Category, Price
FROM Products
WHERE Category IN ('Furniture', 'Stationery')
AND Price BETWEEN 50 AND 5000;
SELECT Name FROM Products WHERE Name LIKE 'N%';
Name Category Price Chair Furniture 4500.00 Notebook Stationery 60.00 Name Notebook
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- IN keeps only Furniture and Stationery products (Desk, Chair, Pen, Notebook).
- BETWEEN 50 AND 5000 removes Desk (12000) and Pen (20).
- LIKE 'N%' matches names that start with N.
Real-world use case#
Search filters on a shopping site — category, price range and “name contains” — become WHERE conditions.
Common mistakes#
This is never true. Write WHERE Column IS NULL.
WHERE Category = 'A' OR Category = 'B' AND Price < 100 applies the price filter only to B.
LIKE '%phone' cannot use an index seek. Prefer LIKE 'phone%' or full-text search.
Best practices#
- Use parentheses to make intent explicit
- Use IS NULL / IS NOT NULL
- Keep columns un-wrapped by functions so indexes can be used
- Pass values as parameters from applications
Remember this#
WHERE filters rows before anything else.
= NULL never works — use IS NULL.
LIKE 'A%' = starts with A.
Practice exercise#
Your task: Find Electronics products that cost less than 1000.
Show solution
SELECT Name, Price FROM Products WHERE Category = 'Electronics' AND Price < 1000; -- Mouse 700.00
Mini quiz#
Is BETWEEN 50 AND 100 inclusive?
Want more? Practise all SQL Server MCQs · SQL Server interview questions
My notes#
Saved in this browser.