n Pruning and Selection for details. FOR PORTION OF -------------- MariaDB starting with 10.4.3 ---------------------------- See Application Time Periods - Deletion by Portion. RETURNING --------- It is possible to return a resultset of the deleted rows for a single table to the client by using the syntax DELETE ... RETURNING select_expr [, select_expr2 ...]] Any of SQL expression that can be calculated from a single row fields is allowed. Subqueries are allowed. The AS keyword is allowed, so it is possible to use aliases. The use of aggregate functions is not allowed. RETURNING cannot be used in multi-table DELETEs. MariaDB starting with 10.3.1 ---------------------------- Same Source and Target Table ---------------------------- Until MariaDB 10.3.1, deleting from a table with the same source and target was not possible. From MariaDB 10.3.1, this is now possible. For example: DELETE FROM t1 WHERE c1 IN (SELECT b.c1 FROM t1 b WHERE b.c2=0); MariaDB starting with 10.3.4 ---------------------------- DELETE HISTORY -------------- One can use DELETE HISTORY to delete historical information from System-versioned tables. Examples -------- How to use the ORDER BY and LIMIT clauses: DELETE FROM page_hit ORDER BY timestamp LIMIT 1000000; How to use the RETURNING clause: DELETE FROM t RETURNING f1; +------+ | f1 | +------+ | 5 | | 50 | | 500 | +------+ The following statement joins two tables: one is only used to satisfy a WHERE condition, but no row is deleted from it; rows from the other table are deleted, instead. DELETE post FROM blog INNER JOIN post WHERE blog.id = post.blog_id; Deleting from the Same Source and Target ---------------------------------------- CREATE TABLE t1 (c1 INT, c2 INT); DELETE FROM t1 WHERE c1 IN (SELECT b.c1 FROM t1 b WHERE b.c2=0); Until MariaDB 10.3.1, this returned: ERROR 1093 (HY000): Table 't1' is specified twice, both as a target for 'DELETE' and as a separate source for From MariaDB 10.3.1: Query OK, 0 rows affected (0.00 sec) URL: https://mariadb.com/kb/en/delete/https://mariadb.com/kb/en/delete/