Filtering and Operators
Real queries need precise filtering. SQL gives you a full set of comparison operators, logical connectors, and pattern matching tools. Mastering these lets you find exactly the data you need from millions of records.
Key Concepts
AND, OR, NOT
Combine conditions with AND (both must be true), OR (either can be true), NOT (invert). SELECT * FROM students WHERE grade=10 AND gpa>3.5 finds 10th-graders with high GPAs. Use parentheses to control order of evaluation.
LIKE and Wildcards
LIKE does pattern matching. % matches any sequence of characters. _ matches exactly one. WHERE name LIKE 'A%' matches names starting with A. WHERE email LIKE '%@gmail.com' finds Gmail addresses. LIKE is case-insensitive in MySQL.
IN, BETWEEN, IS NULL
IN checks if a value is in a list: WHERE grade IN (10,11,12). BETWEEN checks a range: WHERE gpa BETWEEN 3.0 AND 4.0. IS NULL finds rows with missing values: WHERE phone IS NULL. IS NOT NULL finds rows that have a value.
🆕 Advanced Filter Lab
Practice AND, OR, LIKE, IN, and BETWEEN filters.
✅ Check Your Understanding
1. What does AND do in a WHERE clause?
2. What does WHERE name LIKE 'J%' match?
3. What does IN (9, 10, 11) do?