sql · level 1 · unit 2 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
keeps only the rows that match.
Picture a sieve. Pour the whole table in, and only the rows you want stay behind. In SQL, the sieve is WHERE, and it goes after the table name.
After WHERE comes a : a test that every row either passes or fails. age = 3 passes for any pet aged exactly 3. Rows that fail are left out.
If no row passes, you still get the column names, then (no rows). That is not an error. It means nothing matched.
SELECT * FROM pets WHERE age = 3; Here = asks a question: is the age equal to 3?
guess first
No pet is that old. What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
SELECT name FROM pets WHERE age = 10;
your turn
Your turn. Find a pet by its age.
The pets are aged 1, 2, 3, 4, 5 and 7. Type one of those ages in the blank and see which pet comes back.
result
Your answer appears here as a table.
fix it
WHERE is in the wrong place. Can you fix it?
result
Your answer appears here as a table.
- Read the error. Which word does it point near?
- The database needs to know the table before it can sieve it.
FROM petsmust come first. - Move WHERE age = 5 to the end, after FROM pets, then press run.
nailed it
you sieved a table down to size. :D
WHEREkeeps only the rows that pass a condition.WHEREgoes after the table name.(no rows)means nothing matched. It is not an error.
new words in your collection
- WHERE
- condition
This lesson isn’t saved. A free account remembers every lesson you finish.