You can delete from multiple tables (which don’t have foreign keys set up) using one query if you create it using the following syntax:
DELETE a.*, b.* FROM [table1] as a, [table2] as b WHERE a.[idcol] = b.[idcol] AND a.[idcol] = 9;
You could even delete from more than 2 tables…
DELETE a.*, b.*, c.* FROM [table1] as a, [table2] as b, [table3] as c WHERE a.[idcol] = b.[idcol] AND b.[idcol2] = c.[idcol2] AND a.[idcol] = 5;
That should save you some writing a fair bit of sql. Happy (and careful) deleting.
One Reply to “Delete From Two Or More Tables With One MySQL Query”
Ultimate Query, and easy to use…
Comments are closed.