BBampaa

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 →
About 5–10 minutes · no sign-up needed

Example

Remove rows you don't want

DELETE FROM orders
WHERE revenue = 0

Result:

order_idcategoryrevenue
O2001Electronics299.99
O2003Clothing89.00
O2004Electronics149.50

Step by step

  1. The table that loses rows.
    DELETE FROM orders WHERE revenue = 0
  2. Only these go. Leave it out and every row goes.
    DELETE FROM orders WHERE revenue = 0

Practice

Try each one in your head first, then open the answer.

1. Remove the 0.00 test order from orders.
DELETE FROM orders WHERE revenue = 0
2. 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 = 0
5. Remove the Clothing orders under 100 from orders.
DELETE FROM orders WHERE category = 'Clothing' AND revenue < 100

Learn 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 →
About 5–10 minutes · no sign-up needed