Among other questions, this one asked how to delete from a join.
My question: How much of this is standard SQL? On which databases would this actually work (most not
this will actually work in Oracle. The FROM keyword is optional: DELETE (query)
is the same as DELETE FROM (query)
.
The rules to DELETE a JOIN are the same as the rules to update a JOIN: Oracle will modify the rows from only one table and only if there is no ambiguity in identifying the rows of the base table. Look in this SO or this SO for example.
Let's build a small example:
CREATE TABLE t_parent (ID NUMBER PRIMARY KEY, NAME VARCHAR2(10));
CREATE TABLE t_child (ID NUMBER PRIMARY KEY,
parent_id NUMBER REFERENCES t_parent);
INSERT INTO t_parent VALUES (1, 'a');
INSERT INTO t_child VALUES (1, 1);
INSERT INTO t_child VALUES (2, 1);
You can delete rows from the CHILD table:
SQL> DELETE FROM (SELECT t_child.*
2 FROM t_child
3 JOIN t_parent ON t_parent.id = t_child.parent_id
4 WHERE t_parent.name = 'a');
2 rows deleted