Lessons › SQL › Deep Dive: Database Admin & ETL
SQL lesson
DELETE FROM
DELETE FROM permanently removes specific rows from a table based on conditions you set - skip those conditions, though, and it wipes every row, just like TRUNCATE.
Try this lesson free →Example
Deleting Specific Retail Return Rows with DELETE FROM
DELETE FROM returns_staging
WHERE status = 'cancelled'Step by step
- Run DELETE FROM with no WHERE and every row is gone. Almost never what you want.
-- Don't do this: DELETE FROM returns_staging; - WHERE narrows DELETE to just the rows that match. Only matching rows are removed.
DELETE FROM returns_staging WHERE status = 'cancelled'; - BEGIN ... DELETE ... and ROLLBACK or COMMIT lets you preview what would be deleted before committing.
BEGIN; DELETE FROM returns_staging WHERE status = 'cancelled'; -- inspect the result, then: COMMIT; -- or ROLLBACK;
Practice
1. Write a DELETE statement to remove rows from products where product_id equals 'P2001'.
DELETE FROM products WHERE product_id = 'P2001'2. Write a DELETE statement to remove rows from customers where phone equals '555-382-9104'.
DELETE FROM customers WHERE phone = '555-382-9104'3. Write a DELETE statement to remove rows from orders where customer_id equals 'C101'.
DELETE FROM orders WHERE customer_id = 'C101'4. Write a DELETE statement to remove rows from inventory where warehouse equals 'East'.
DELETE FROM inventory WHERE warehouse = 'East'5. Write a DELETE statement to remove rows from suppliers where country equals 'Norway'.
DELETE FROM suppliers WHERE country = 'Norway'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 →