Search code examples
mysqlfetchsql-delete

Get field value before delete it


I have two table categories ( hierarchical structure ) and attachment that have relations together.

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?


Solution

  • Try:

    delete c,a category c 
     join attachment a on c.id=a.category_id 
     where c.lft between @left and @right