Basic · Lesson 2 of 14
SELECT and WHERE
Pick columns and filter rows.
SELECT projects columns
SELECT decides which columns come back. Always pick the exact ones you need: it is faster, and interviewers read it as discipline.
WHERE filters rows
WHERE keeps only rows whose condition is true. Comparisons include =, <>, >, <, and you combine conditions with AND, OR, and NOT. Text literally is quoted with single quotes.
The order trap
WHERE runs before selection, so you can filter on any underlying column even if you do not select it. You cannot filter on a SELECT alias inside WHERE, because the alias does not exist yet.
Examples
Exact equality
Rows where country is exactly India.
SELECT name, country FROM users WHERE country = 'India';
Range of values
Everything released in 2023 or later.
SELECT title, release_year FROM content WHERE release_year >= 2023;
Combine with AND
Both conditions must hold for a row to survive.
SELECT name, plan FROM users WHERE plan = 'Premium' AND country = 'India';