Removing from cart
- SQL course
- Beginner
- Lesson 46/115
- 5 min
Write the DELETE query to remove an item from the cart.
Removing from cart
To remove a line from the cart you use DELETE. WHERE picks which row to delete.
DELETE FROM cart
WHERE id = 2;This query removes line 2 from the cart.
Rows are deleted from cart. Only the rows where id = 2 holds are affected.
Removing from cart — details
Deletion cannot be undone. DELETE without WHERE empties the whole cart; always use WHERE.
Practice Removing from cart
Delete the line with id=2 from cart.
Starter code
-- remove from cart
DELETE FROM cart
WHERESample solution
DELETE FROM cart
WHERE id = 2Expected output
1 satır silindi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Delete row
DELETE ____ cart
WHERE id = 2;
DELETE FROM cart
WHERE id = 2;
Explanation: Removing an item uses DELETE FROM cart WHERE id = 2.
2 Which statement removes from the cart?
- DELETE Correct answer
- INSERT
- UPDATE
- SELECT
Explanation: DELETE removes a row.
3 Removing from cart: match the terms
| Term | Meaning |
|---|---|
DELETE |
delete |
FROM |
table |
WHERE |
condition |
UPDATE |
update |