DELETE statement
Single-table and multi-table DELETE with ORDER BY, LIMIT and RETURNING, as the Raft DB parser accepts it.
DELETE removes rows. A statement is all or nothing.
Syntax#
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM [db_name.]tbl_name
[WHERE condition]
[ORDER BY order_expr [ASC | DESC] [, ...]]
[LIMIT row_count]
[RETURNING select_item [, select_item] ...]
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] tbl_name [, tbl_name] ...
FROM table_references
[WHERE condition]
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name [, tbl_name] ...
USING table_references
[WHERE condition]Arguments#
| Name | Meaning | Default |
|---|---|---|
LOW_PRIORITY, QUICK, IGNORE | Accepted. | off |
WHERE | Rows to remove. Without it every row goes (TRUNCATE TABLE is faster and resets the counter). | all rows |
ORDER BY, LIMIT | Single table form only; LIMIT takes one number. | none |
RETURNING | The removed rows as a result set (single-table form). See RETURNING. | none |
Remarks#
- In the multi-table forms the rows are found by the
SELECTexecutor; every table named beforeFROM(or afterFROMin theUSINGform) loses its matching rows. - A parent row that other rows refer to:
RESTRICT/NO ACTIONrefuse (error 1451);CASCADEdeletes the referring rows (depth 15);SET NULLclears them. BEFORE DELETEandAFTER DELETEtriggers run for the single-table form. A multi-tableDELETEdoes not run triggers yet.- A subquery on the table being deleted from is error 1093.
- Privileges:
DELETEon the table;SELECTon the columnsWHEREreads. - Deleting from a view of one table is done on its table.
- MariaDB's
DELETE ... RETURNINGis not restricted to the MariaDB dialect by the parser; it is checked against MariaDB.
Examples#
Example:
DELETE FROM e WHERE id IN (SELECT id FROM x);
DELETE a, b FROM a JOIN b ON a.id = b.id WHERE a.id = 1;
DELETE FROM a USING a JOIN b ON a.id = b.id;
DELETE FROM t WHERE id IN (2, 3) RETURNING id, name;
DELETE FROM t ORDER BY id LIMIT 2 RETURNING id;