×

sql · level 1 · unit 6 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. 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.