SQL ยท Chapter 5 of 42
SQL WHERE
WHERE filters rows using conditions. Combine multiple conditions with AND, OR and NOT.
Operators: `=`, `<>` (not equal), `>`, `<`, `>=`, `<=`, `BETWEEN`, `LIKE`, `IN`, `IS NULL`.
Syntax
SELECT ... FROM table WHERE condition;Combining conditions
Use AND / OR / NOT. Parentheses control precedence.
Not equal
SQL uses `<>` (standard) or `!=` (many dialects) for 'not equal'.
Example 1 (sql)
SELECT * FROM users WHERE age >= 18 AND country = 'India';Output
name | age | country
Ana | 25 | IndiaTwo conditions combined with AND.
Example 2 (sql)
SELECT * FROM products WHERE price BETWEEN 100 AND 500;Output
product | price
Book | 250
Headphone | 499BETWEEN is inclusive on both ends.
Key points
- WHERE filters rows before grouping.
- Combine with AND / OR / NOT.
- Use `BETWEEN`, `IN`, `LIKE`, `IS NULL` for common patterns.
- Use `<>` for 'not equal'.
๐ก Note: `WHERE col = NULL` NEVER matches. Use `WHERE col IS NULL` instead.
