Use the JOIN in the DELETE .
DELETE p, pa FROM pets p JOIN pets_activities pa ON pa.id = p.pet_id WHERE p.order > :order AND p.pet_id = :pet_id
Alternatively you can use ...
DELETE pa FROM pets_activities pa JOIN pets p ON pa.id = p.pet_id WHERE p.order > :order AND p.pet_id = :pet_id
... to remove only from pets_activities
See http://dev.mysql.com/doc/refman/5.0/en/delete.html
For single table deletions, but with referential integrity, there are other ways to run with EXISTS, DO NOT EXIST, IN, NOT IN, etc. But above, where you specify from which tables to delete using an alias before FROM, a sentence can easily save you from several rather bottlenecks. I tend to access EXISTS 99% of the time, and then there is 1% where the MySQL syntax takes a day.
cadman Jul 11 2018-12-12T00: 00Z
source share