sql · level 1 · unit 6 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
changes values. WHERE says which rows.
Rex has had a birthday. changes the age, and WHERE name = 'Rex' makes sure only Rex's row changes.
SET names the column and its new value. To change two columns at once, put a comma between them, like SET price = 90, stock = 10.
Always write the WHERE. Without it, UPDATE changes every single row in the table, and there is no undo button.
UPDATE pets SET age = 4 WHERE name = 'Rex';
SELECT * FROM pets WHERE name = 'Rex'; Try your WHERE in a SELECT first, and when it finds the right rows, use it in the UPDATE.
guess first
Prices go up. What will crisps cost now?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
UPDATE snacks SET price = price + 10 WHERE kind = 'savoury';
SELECT name, price FROM snacks WHERE name = 'crisps';
your turn
Your turn. Restock the popcorn.
Popcorn has run out. Type how many bags have arrived in the blank, then press run to see the new stock.
result
Your answer appears here as a table.
fix it
Only Rex had a birthday. Can you fix it?
result
Your answer appears here as a table.
- Biscuit is 7, but the result says 4. Which rows did the
UPDATEchange? - Without
WHERE,UPDATEchanges every row in the table. - Add WHERE name = 'Rex' before the semicolon on line 1, then press run.
nailed it
you changed one row and left the rest alone. :D
UPDATE table SET column = valuechanges values.- Always add
WHERE, or every row changes. SET price = price + 10works from the old value.
new words in your collection
- UPDATE
- SET
This lesson isn’t saved. A free account remembers every lesson you finish.