Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

where-filtering

WHERE filtering

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
beginner

This lesson

This lesson teaches WHERE filtering: the SQL patterns, schema habits, and query reasoning you need before advancing in SQL.

Teams query WHERE filtering on every SQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply WHERE filtering in contexts like: Postgres, MySQL, SQLite, warehouses, and ORMs that still expose SQL.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path. Also always preview destructive UPDATE/DELETE with SELECT ... WHERE first.

When you can explain the previous lesson's ideas without copying example queries verbatim.

The WHERE clause filters rows before projection and grouping. Correct filters keep queries fast and prevent accidental mass updates when you reuse the same condition in DML.

Comparison operators

SELECT id, name, total
FROM orders
WHERE total >= 50;

SELECT id, name
FROM customers
WHERE name <> 'Ada';

Practice: Run in SQLite, DB Fiddle, or Postgres. Create the customers/orders sample from the relational-model lesson if needed.

AND, OR, IN, BETWEEN

SELECT *
FROM orders
WHERE customer_id = 1
  AND total BETWEEN 10 AND 100;

SELECT *
FROM orders
WHERE status IN ('shipped', 'pending');

Combine predicates carefully—use parentheses when mixing AND and OR to avoid logic bugs.

Pattern matching

SELECT name, email
FROM customers
WHERE email LIKE '%@example.com';

SELECT name
FROM customers
WHERE name LIKE 'A%';

LIKE uses % (any length) and _ (one char). Case sensitivity depends on database collation.

Important interview questions and answers

  1. Q: WHERE vs HAVING?
    A: WHERE filters rows before grouping; HAVING filters groups after aggregation.
  2. Q: LIKE performance?
    A: Leading wildcards ('%x') often prevent index use—consider full-text search for heavy text queries.

Self-check

  1. Which operator selects a numeric range inclusively?
  2. Why put filters in WHERE instead of filtering in application code?

Tip: Always preview UPDATE/DELETE WHERE clauses with the same predicate in SELECT first.

Interview prep

WHERE vs HAVING?

WHERE filters rows before grouping; HAVING filters groups after aggregation.

LIKE wildcard?

% matches any length; _ matches one character.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • AND vs OR?
  • Preview DELETE?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump