Learn SQL
SQL WHERE Clause Explained: Filtering Rows with AND, OR, and LIKE
Filtering is where SQL starts to feel useful: keep only the rows that answer your question, then combine conditions as your questions get sharper.
On This Page
Filtering turns tables into answers
A SELECT query can show you a table. A WHERE clause turns that table into an answer. Instead of reading every row, you tell SQL which rows matter for the question in front of you.
SQL for Files lets you practice this in the browser with guided lessons or your own CSV, JSON, and Parquet files. Queries run locally with DuckDB WASM, so you can learn filtering without setting up a database server.
WHERE keeps rows that match a condition
The WHERE clause checks each row against a condition. Rows that pass stay in the result. Rows that do not pass are left out.
SELECT *
FROM employees
WHERE salary > 80000;Comparison operators like equals, not equals, greater than, and less than are the building blocks of row-level filtering.
Combine conditions with AND and OR
Real questions often need more than one condition. AND means every condition must be true. OR means at least one condition must be true.
SELECT *
FROM employees
WHERE department = 'Marketing'
AND salary > 70000;Use parentheses when mixing AND and OR
Parentheses make your intended logic obvious and prevent subtle mistakes when multiple conditions are combined.
Find text patterns with LIKE
LIKE searches text using patterns. The percent sign matches any sequence of characters, while the underscore matches exactly one character.
SELECT name
FROM employees
WHERE name LIKE '%li%'
ORDER BY name;In DuckDB, LIKE is case-sensitive and ILIKE is available when you want case-insensitive matching.
Practice the Filtering Data chapter
- Start with WHERE Clause Basics to filter salary and department rows.
- Use Combining Conditions to practice AND, OR, and parentheses.
- Finish with Pattern Matching with LIKE to search text values.
Continue in the editor
Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.
Open editorRelated Learn SQL lessons
Related guides
Introduction to SQL: SELECT, Columns, Aliases, and Sorting Results
Your first SQL queries do not need to be complicated. Start with SELECT, choose the columns you need, name results clearly, and sort rows intentionally.
SQL NULL Explained: How Missing Values Work and Why They Matter
NULL is SQL's way of saying a value is missing or unknown — and it behaves differently from almost every other value beginners expect.
How to Query CSV Files with SQL in Your Browser
Use SQL for Files as a local CSV analysis workspace: add a file, inspect the generated table, write SQL, and export the rows you need.