Reading Data
WHERE
WHERE filters rows so you only get the ones you need.
SELECT name FROM students WHERE city = 'Lahore';
SELECT name FROM students WHERE marks >= 80 AND city = 'Lahore';
SELECT name FROM students WHERE city IN ('Lahore', 'Karachi');
SELECT name FROM students WHERE marks BETWEEN 70 AND 90;
SELECT name FROM students WHERE name LIKE 'S%'; -- starts with S
SELECT name FROM students WHERE city IS NULL;| Operator | Meaning |
|---|---|
= <> | Equal / not equal |
> < >= <= | Comparisons |
AND OR NOT | Combine conditions |
IN (...) | Matches any value in a list |
BETWEEN a AND b | In a range (inclusive) |
LIKE | Pattern: % = any characters, _ = one character |
IS NULL | Has no value |