开发者

Get field value before delete it

开发者 https://www.devze.com 2023-02-25 01:36 出处:网络
I have two table categories ( hierarchical structure ) and attachment that have relations togeth开发者_如何学Cer.

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;

0

精彩评论

暂无评论...
验证码 换一张
取 消