Lessons › SQL › Chapter 7: Creating and changing tables
SQL lesson
DELETE FROM
DELETE removes rows from a table. WHERE says which ones. The table stays, with the rest of its rows. As with UPDATE, a DELETE with no WHERE removes every row. So check with a SELECT first.
Try this lesson free →Example
Remove rows you don't want
DELETE FROM orders
WHERE revenue = 0| order_id | category | revenue |
|---|---|---|
| O2001 | Electronics | 299.99 |
| O2003 | Clothing | 89.00 |
| O2004 | Electronics | 149.50 |
Step by step
- The table that loses rows.
DELETE FROM orders WHERE revenue = 0 - Only these go. Leave it out and every row goes.
DELETE FROM orders WHERE revenue = 0
Practice
1. Remove the 0.00 test order from orders.
DELETE FROM orders WHERE revenue = 02. Remove return R2 from returns.
DELETE FROM returns WHERE return_id = 'R2'3. Remove every order placed before 2024-03-03 from orders.
DELETE FROM orders WHERE order_date < '2024-03-03'4. Remove every row with 0 units from stock_counts.
DELETE FROM stock_counts WHERE units = 05. Remove the Clothing orders under 100 from orders.
DELETE FROM orders WHERE category = 'Clothing' AND revenue < 100Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →