I have 3 MySQL tables (food
, apple
, and orange
).
I want to delete rows from:
apple(idapple, iduser, name)
orange(idornge, iduser, name)
When deleting a row in food(iduser, name)
using one trigger?
Here is my trigger so far:
CREATE TRIGGER `food_before_delete`
AFTER DELETE ON `food`
FOR EACH ROW
DELETE FROM apple, orange
WHERE
apple.iduser=OLD.iduser and
orange.iduser=OLD.iduser
But it won't compile. How can make a trigger that deletes from two tables at once?
Something simpler maybe?
DELETE f,a,o FROM
food AS f
LEFT JOIN apple AS a USING (iduser)
LEFT JOIN orange AS o USING (iduser)
WHERE f.name = ...
No trigger needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With