Deletes rows from the specified table.

Syntax

DELETE FROM <table> [[AS] <alias>] [USING <from_item>] WHERE <condition>

Parameters

ParameterDescription
<table>The table to delete rows from.
<from_item>A table expression allowing columns from other tables to appear in the WHERE condition. This uses the same syntax as the FROM clause of a SELECT statement; for example, an alias for the table name can be specified. Do not repeat the target table as a from_item unless you wish to set up a self-join (in which case it must appear with an alias in the from_item).
<condition>A Boolean expression. Only rows for which this expression returns true will be deleted. Condition can have subqueries doing semi-join with other table(s).

The DELETE FROM <table> without <expression> will delete all rows from the table. It is equivalent to a TRUNCATE TABLE statement.

Remarks

Deleted rows are marked for deletion, but are not automatically cleaned up. You can monitor fragmentation in information_schema.tables to understand how many rows are marked for deletion out of total rows; fragmentation = (rows marked for deletion / total rows). Total row count in information_schema.tables excludes the number of rows marked for deletion. Query performance is not materially impacted by delete marks.

To mitigate fragmentation, use the VACUUM command to manually clean up deleted rows.

Example

The following example deletes entries from the products table where the quantity is less than 10:

DELETE FROM products WHERE quantity < 10

Table before:

productquantity
wand9
broomstick21
robe1
quidditch gloves10
cauldron16
quill100

Table after:

productquantity
broomstick21
quidditch gloves10
cauldron16
quill100

Example specifying other tables in the USING clause

This example deletes all the products from stores that went out of business.

DELETE FROM products USING suppliers WHERE products.product = suppliers.product AND suppliers.store = 'Ollivanders'

Table products before:

productquantity
wand9
broomstick21
robe1
quidditch gloves10
cauldron16
quill100

Table suppliers before:

productstore
wandOllivanders
broomstickQuality Quidditch Supplies
robeMadam Malkin’s
quidditch glovesQuality Quidditch Supplies
cauldronApothecary
quillAmanuensis Quills

Table products after:

productquantity
broomstick21
robe1
quidditch gloves10
cauldron16
quill100