Oracle 5.0 Reference Manual page 1083

Table of Contents

Advertisement

No other sessions can access the tables involved while
operation is not subject to concurrency problems. See
You can specify multiple tables in a
depending on the particular condition in the
in a multiple-table DELETE. The
LIMIT
Its syntax is described in
For the first multiple-table syntax, only matching rows from the tables listed before the
deleted. For the second multiple-table syntax, only matching rows from the tables listed in the
clause (before the
USING
at the same time and have additional tables that are used only for searching:
DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;
Or:
DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;
These statements use all three tables when searching for rows to delete, but delete matching rows only
from tables
and t2.
t1
The preceding examples use
of join permitted in
SELECT
that have no match in t2, use a
t1
DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;
The syntax permits
.*
If you use a multiple-table
constraints, the MySQL optimizer might process tables in an order that differs from that of their parent/
child relationship. In this case, the statement fails and rolls back. Instead, you should delete from a
single table and rely on the
be modified accordingly.
Note
If you declare an alias for a table, you must use the alias when referring to the
table:
DELETE t1 FROM test AS t1, test2 WHERE ...
Table aliases in a multiple-table
the statement. Declaration of aliases other than in the
because that can lead to ambiguous statements that have unexpected results such as deleting rows
from the wrong table. This is such a statement:
DELETE t1 AS a2 FROM t1 AS a1 INNER JOIN t2 AS a2;
For alias references in the list of tables from which to delete rows in a multiple-table delete, the default
database is used unless one is specified explicitly. For example, if the default database is db1, the
following statement does not work because the unqualified alias reference
database of db1:
DELETE a1, a2 FROM db1.t1 AS a1 INNER JOIN db2.t2 AS a2
WHERE a1.id=a2.id;
To correctly match an alias that refers to a table outside the default database, you must explicitly
qualify the reference with the name of the proper database:
DELETE a1, db2.a2 FROM db1.t1 AS a1 INNER JOIN db2.t2 AS a2
DELETE
statement to delete rows from one or more tables
DELETE
WHERE
table_references
Section 13.2.8.2,
"JOIN
clause) are deleted. The effect is that you can delete rows from many tables
JOIN, but multiple-table
INNER
statements, such as
LEFT
JOIN:
after each
for compatibility with Access.
tbl_name
statement involving
DELETE
capabilities that
ON DELETE
should be declared only in the
DELETE
1063
Syntax
RENAME TABLE
Section 13.1.20,
clause. However, you cannot use
clause lists the tables involved in the join.
Syntax".
DELETE
JOIN. For example, to delete rows that exist in
LEFT
tables for which there are foreign key
InnoDB
provides to cause the other tables to
InnoDB
table_references
executes, so the rename
"RENAME TABLE
Syntax".
ORDER BY
clause are
FROM
FROM
statements can use other types
table_references
part should be avoided
is interpreted as having a
a2
or
part of

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents