01 / 04
You want fewer rows
SELECT was handing back every row. But more often you want only the rows that match — "dishes at 600 or under", "just the noodles".
The job that if does in JavaScript is done here by WHERE.
Pull rows out, then filter them
INPUT · Slides
01 / 04
SELECT was handing back every row. But more often you want only the rows that match — "dishes at 600 or under", "just the noodles".
The job that if does in JavaScript is done here by WHERE.
02 / 04
Write SELECT ... FROM ... WHERE condition; — the condition goes on after FROM.
A text value is wrapped in ' (single quotes). That is the SQL rule, and it differs from JavaScript's ", so watch out.
SELECT * FROM menus WHERE category = 'noodles';Result
only the two rows, tofu udon and soy ramen
03 / 04
For number conditions you have the comparison operators.
price < 600 … under 600price <= 600 … 600 or underprice > 600 … over 600Much like JavaScript, except that "equals" is a single =, not ===. That is the big difference.
SELECT name, price FROM menus WHERE price <= 600;04 / 04
"Is not equal" is written <> (!= works too).
WHERE narrows the rows, SELECT narrows the columns. You can now choose both.
SELECT name FROM menus WHERE category <> 'noodles';