0

I'm trying to do a delete on two tables at once.

sucessfully does it with update,

UPDATE table1 INNER JOIN table2 ON table2.table1_id = table1.ID SET table1.whatever = Whatever, table2.whateveer = Whatever

is there a way to do this with the DELETE function

DELETE table1 INNER JOIN table2 ON table2.table1_id = table1.id WHERE table1.ID = 1

doesn't work

thanks in advanced.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jlego
0

When deleteing from multiple tables, you need to specify what is being deleted. There are two available syntaxes:

DELETE table1, table2 
FROM table1 INNER JOIN table2 ON table1.id = table2.id 
WHERE table1.id = 1

or:

DELETE FROM table1, table2 
USING table1 INNER JOIN table2
WHERE table1.id=table2.id AND table1.id = 1

Hope this helps.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.