You may well delete from several tables in one of the statements with MySQL . Your requirements will work using the following query:
DELETE menu, pages FROM menu JOIN pages WHERE menu.name = 'some name' AND pages.title = 'some title'
Or:
DELETE FROM menu, pages USING menu JOIN pages WHERE menu.name = 'some name' AND pages.title = 'some title'
There is one example with these examples: this requires the existence of both values.
There should be more ways to get the desired result, I think, without this restriction (using other types of JOIN , I would have thought), but I could not figure out how this should work.
If the rows you want to delete are somehow connected to each other using foreign keys (and you are not using foreign key constraints with InnoDB tables), it should be even easier to do what you want. Something like this should work then:
DELETE menu, pages FROM menu LEFT JOIN pages ON menu.pageId = page.id
Be careful with these examples. First experiment with the test environment, as Iām not sure that the consequences are 100% accurate, to be honest; I just wanted to give a hint that several tables are deleted at once.
source share