Description

This function allows you to delete one or more rows of data from a specified table. By using the WHERE clause, you can precisely specify the rows that need to be deleted.

Syntax

DELETE FROM table_name WHERE condition;

Parameters

  • <table_name>: Specify the name of the table from which you want to delete data.
  • <condition>: Define the condition for the delete operation, which can use various expressions and subqueries in the WHERE clause.

Example

  1. Delete all employees older than 30 years from the table named "employees":
    DELETE FROM employees WHERE age > 30;
  2. Delete all products with a price lower than 50 yuan from the "products" table:
    DELETE FROM products WHERE price < 50;
  3. Delete all customer records named "张三" in the "customers" table:
DELETE FROM customers WHERE name = '张三';
4. Delete all canceled orders from the "orders" table through a subquery:
DELETE FROM orders WHERE order_id IN (SELECT order_id FROM order_details WHERE status = 'cancelled');

Precautions

  • Please use the DELETE statement with caution, as the delete operation is irreversible.
  • Before performing a delete operation, ensure that you have backed up the relevant data to prevent accidental deletion of important information.
  • You can use the WHERE clause to limit the scope of deletion. If no WHERE condition is specified, all rows in the table will be deleted.