CodeBlanks Logo Icon CodeBlanks

DELETE basics

Delete rows with DELETE.

DELETE basics

With DELETE FROM you remove rows from a table. WHERE picks which rows to delete.

DELETE FROM products
WHERE id = 1;

This query removes product 1.

Rows are deleted from products. Only the rows where id = 1 holds are affected.

DELETE basics — details

Without WHERE, DELETE removes every row; always give a condition. Deleted data cannot be undone.

Practice DELETE basics

Delete the row with id=1 from products.

Starter code

query.sql
-- delete row
DELETE FROM products
WHERE

Sample solution

query.sql
DELETE FROM products
WHERE id = 1

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 What happens if WHERE is missing in DELETE?

  • Only the first row
  • All rows are deleted Correct answer
  • Raises an error
  • No rows

Explanation: DELETE without WHERE deletes every row.

2 Delete row

Question
DELETE ____ products
WHERE id = 1;
Answer
DELETE FROM products
WHERE id = 1;

Explanation: DELETE FROM table WHERE condition deletes only the rows that match.

3 DELETE basics: match the terms

Term Meaning
DELETE delete
FROM table
WHERE condition
UPDATE update

All lessons in Beginner