tags:

views:

35

answers:

4

Lets say I have 20 comments that are related to article_id 76 will I have to count all the article ids that have an article_id 76 and then run a foreach loop for all the comments related to article 76 or can I delete all the comments related to that article using a query?

SELECT article_id FROM articles_comments WHERE article_id = 76
+8  A: 
DELETE FROM articles_comments WHERE article_id = 76;
coding.mof
Beat me by 9 seconds, well done.
fredley
will this delete all article rows with an article id of 76 or will I have to run a foreach loop?
aatteot
@aatteot It will delete all of them
fredley
@fredley: Thanks!@aatteot: It will delete all records having the field article_id set to the given value.
coding.mof
+1  A: 

DELETE FROM articles_comments WHERE article_id = 76

fredley
will this delete all article rows with an article id of 76 or will I have to run a foreach loop?
aatteot
+1  A: 

Just one operation:

 delete from article_comments where article_id = 76
Michael Pakhantsov
will this delete all article rows with an article id of 76 or will I have to run a foreach loop?
aatteot
A: 

No need for any looping.

This one query will delete all the comments related to article_id 76

DELETE FROM articles_comments 
WHERE article_id = 76;
codaddict
will this delete all article rows with an article id of 76 or will I have to run a foreach loop?
aatteot
Yes, this will delete **all** rows from `article_comments` which have `article_id` equal to `76`
codaddict