batch delete records in database table

Go To StackoverFlow.com

1

I want to delete multiple records at once.

I have two tables, one that contains

comments: comment_id, comment, author_id
news_comments: news_id, comment_id

I want to delete all records from the news_comments where author_id = 1 in the comments table.

I tried doing this, but it gave me an error about the sub query returning more than one item:

delete from news_items where comment_id = 
(select comment_id from comments where author_id = 1)
2012-04-03 20:09
by Brad


5

delete from news_items where comment_id IN 
(select comment_id from comments where author_id = 1)
                                        ^^
                                        IN
2012-04-03 20:11
by cagcowboy


2

try this

delete from news_items where comment_id in 
(select comment_id from comments where author_id = 1)
2012-04-03 20:11
by hkutluay
Ads