</>
Skip to content
MySQL lessons (18/48)

MySQL — Delete

Basic DELETE

DELETE FROM users WHERE id = 1;

Delete Multiple Rows

DELETE FROM users WHERE age < 18;

Delete All Rows

DELETE FROM users;

DELETE Examples

-- Delete single row
DELETE FROM users WHERE id = 5;

-- Delete with multiple conditions
DELETE FROM orders
WHERE status = 'cancelled' AND created_at < '2023-01-01';

-- Delete with LIMIT
DELETE FROM logs
WHERE created_at < '2022-01-01'
LIMIT 1000;

-- Delete from multiple tables
DELETE users, orders
FROM users
INNER JOIN orders ON users.id = orders.user_id
WHERE users.is_active = FALSE;

WARNING

-- Always use WHERE clause!
DELETE FROM users; -- Deletes ALL rows!

-- Test with SELECT first
SELECT * FROM users WHERE condition;

Best Practices

  1. Always use WHERE clause
  2. Test with SELECT first
  3. Use LIMIT for large deletions
  4. Consider soft deletes (is_active flag)
  5. Backup before bulk deletes

Mini Practice

Write MySQL code that:

  1. Deletes a single row
  2. Deletes multiple rows
  3. Uses LIMIT for deletion
  4. Tests with SELECT first

Up Next

Next: Learn about Limiting Results.

Related Topics

Frequently Asked Questions about Delete

What is Delete in MySQL?

Delete is a fundamental concept in MySQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Delete?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Delete.

Why is Delete important in MySQL?

Delete is essential for MySQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.