Skip to main content

Filtering with WHERE

WHERE narrows result sets.

It is the core tool for turning broad table scans into focused answers.

Core Concepts

flowchart LR
A[All table rows] --> B[Apply WHERE condition]
B --> C[Only matching rows returned]
Filter typeExample
EqualityWHERE status = 'open'
Numeric comparisonWHERE amount > 100
Combined logicWHERE status = 'open' AND priority = 'high'

Code Examples

-- Setup issues table for filtering demo.
CREATE TABLE issues_where (
issue_id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
status TEXT NOT NULL,
severity INTEGER NOT NULL
);

INSERT INTO issues_where (title, status, severity)
VALUES
('Login bug', 'open', 3),
('UI typo', 'closed', 1),
('Crash on save', 'open', 5);
Expected output
Table created and three rows inserted.
-- Return only open issues.
SELECT issue_id, title, severity
FROM issues_where
WHERE status = 'open';
issue_idtitleseverity
1Login bug3
3Crash on save5

SQLite-Specific Nuances

SQLite Nuance

SQLite evaluates WHERE expressions per row and returns rows where the condition is true.

Common Pitfalls / Best Practices

Pitfall

Using text values with inconsistent capitalization and expecting exact matches.

Best Practice

Keep status/category values standardized (or normalized) so filters stay simple and reliable.

Quick Challenge

Return issues with severity >= 4.

View Solution
SELECT issue_id, title, severity
FROM issues_where
WHERE severity >= 4;
issue_idtitleseverity
3Crash on save5