In production databases holding millions of records, you rarely want to retrieve all rows at once. The WHERE clause specifies the search condition that rows must satisfy to be selected for reading, updating, or deleting. The database evaluates the condition for each row: if the condition evaluates to TRUE, the row is returned; if FALSE or UNKNOWN (NULL), it is discarded.
| Operator | Meaning | Example Query Expression |
|---|---|---|
| = | Equal to | WHERE course = 'BCA' |
| <> or != | Not equal to | WHERE status <> 'Inactive' |
| > | Greater than | WHERE gpa > 3.50 |
| < | Less than | WHERE salary < 40000 |
| >= | Greater than or equal to | WHERE age >= 18 |
| <= | Less than or equal to | WHERE balance <= 0.00 |
-- 1. Filter by numeric threshold
SELECT student_id, first_name, gpa
FROM students
WHERE gpa >= 3.80;
-- 2. Filter by exact string match
SELECT student_id, first_name, course
FROM students
WHERE course = 'BCA';
-- 3. Filter by date comparison
SELECT student_id, first_name, enrollment_date
FROM students
WHERE enrollment_date >= '2026-01-01';
When an indexed column is evaluated in a WHERE clause (e.g., WHERE student_id = 105), the database traverses a B+ Tree index in (O(\log N)) time, reading only 2 or 3 disk blocks. Without an index on that column, the engine must perform a Full Table Scan (FTS), inspecting every single row on disk!
WHERE salary = NULL! Always write WHERE salary IS NULL. We will study SQL three-valued logic in detail in the NULL handling class.
Next, let us combine multiple filter criteria using SQL AND, OR, NOT Logical Operators!