0

I'm running into a problem with deleting from multiple tables.

DELETE FROM categories, products
WHERE categories.category_id = products.category_id 
    AND categories.category_id = 4;

Can anyone spot the mistake that I've made? I'm getting the errorcode: 1064

4
  • do you have a database selected? Commented Sep 21, 2014 at 3:22
  • 2
    stackoverflow.com/questions/3331992/… Commented Sep 21, 2014 at 3:26
  • Can there be an explanation on what I'm doing wrong? Commented Sep 21, 2014 at 3:46
  • it appears that you need to explicitly declare the join, Did you look at the linked question? save for the table name it appears to be exactly what you are trying to do. Commented Sep 21, 2014 at 13:58

1 Answer 1

0

you can make the foreign key on product table as on delete cascade. Then, when you delete category product table references will also be deleted

DELETE FROM categories WHERE  
   categories.category_id = 4;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.