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.

Published 2026-05-09·Updated 2026-05-09

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

  1. Start with WHERE Clause Basics to filter salary and department rows.
  2. Use Combining Conditions to practice AND, OR, and parentheses.
  3. 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 editor