CodeBlanks Logo Icon CodeBlanks

Removing from cart

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

query.sql
-- remove from cart
DELETE FROM cart
WHERE

Sample solution

query.sql
DELETE FROM cart
WHERE id = 2

Expected 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

Question
DELETE ____ cart
WHERE id = 2;
Answer
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

All lessons in Beginner