I have two table categories ( hierarchical structure ) and attachment that have relations togeth开发者_如何学Cer.
delete from category where lft between @left and @right;
and I want to delete from attachment which is related by those category !
What should I do?
Try:
delete c,a category c
join attachment a on c.id=a.category_id
where c.lft between @left and @right
I would suggest using FOREIGH KEYS with InnoDB MySQl and Foreign key constraints and define ON DELETE - CASCADE option for the key that relates categories and attachment tables.
Second one is just DELETE FROM attachments WHERE category_id BETWEEEN @left AND @right;
精彩评论