SQL – WHERE
Filter your query results using the WHERE clause to retrieve only the rows that match your conditions.
Table of Contents
Without WHERE, every query returns the entire table. That might be fine for a table of 8 rows, but imagine a database with 50 million users — you definitely do not want all of them. The WHERE clause is your precision filter; it evaluates each row against a condition and only returns the rows where that condition is true.
You can use comparison operators (=, !=, >, <, >=, <=), check for text patterns, or combine multiple conditions. The WHERE clause is evaluated before columns are selected, which makes it very efficient — the database discards rows it does not need before doing any extra work.
Comparison operators in WHERE
| Operator | Meaning |
|---|---|
| = | Equal to |
| != or <> | Not equal to |
| > / < | Greater / Less than |
| >= / <= | Greater or equal / Less or equal |
| BETWEEN | Within a range |
| IN | Matches any value in a list |
| LIKE | Pattern match |
Try It Yourself — Interactive SQL Editor
Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.
Key Points
- WHERE filters happen before SELECT — very efficient
- String comparisons are case-sensitive in most databases
- Always use WHERE in UPDATE and DELETE to avoid changing all rows
- WHERE can use column expressions: WHERE score * 2 > 150
Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.
In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.