sql · level 1 · unit 6 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
removes rows. WHERE keeps you safe.
DELETE FROM snacks WHERE stock = 0 removes every snack that has run out. Like UPDATE, it needs a WHERE to say which rows go.
Without WHERE, DELETE empties the whole table. There is no undo, so check first: run a SELECT with the same WHERE and see which rows it finds.
DELETE takes away whole rows. To empty a single box instead, use UPDATE and set it to NULL.
DELETE FROM snacks WHERE stock = 0;
SELECT name, stock FROM snacks; Here every run starts fresh, but in a real database a deleted row is gone for good.
guess first
Goodbye, darts. How many scores are left?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
DELETE FROM scores WHERE game = 'darts';
SELECT COUNT(*) AS scores_left FROM scores;
your turn
Your turn. Tidy up the pets table.
Pick a species to remove: dog, cat, fish or rabbit. Type it between the quotes, then press run to see who is left.
result
Your answer appears here as a table.
fix it
Only sold-out snacks should go. Can you fix it?
result
Your answer appears here as a table.
- The plan was to remove only the snacks with no stock left. How many rows did this remove?
- Without
WHERE,DELETEremoves every row in the table. - Add WHERE stock = 0 before the semicolon on line 1, then press run.
nailed it
you removed rows with care. :D
DELETE FROM table WHERE ...removes rows.- Without
WHERE, every row is removed. - Check with a
SELECTbefore you delete.
new words in your collection
- DELETE
This lesson isn’t saved. A free account remembers every lesson you finish.