Home › Learn › SQL › Changing data, and the report

DELETE

Lesson 23 of 26. Remove rows.

DELETE FROM products WHERE stock = 0; removes the matching rows. Without a WHERE it empties the table, so the same advice applies: write and check the WHERE as a SELECT first.

Real databases usually protect related data: deleting a product that orders refer to may be refused, or may cascade. The practice data has no such constraints, but the products with zero stock here were never ordered, which is the state a careful deletion checks for.

DELETE FROM orders WHERE ordered_at < '2024-03-10';

Your task

Delete every product whose stock is zero.

Hint 1

WHERE stock = 0

Show the solution
DELETE FROM products WHERE stock = 0;

    Runs SQLite compiled to WebAssembly in this tab; the database is rebuilt before every run.