2012-04-03 60 views
1

我想一次刪除多個記錄。批量刪除數據庫表中的記錄

我有兩個表,一個包含

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

我想從news_comments刪除所有記錄,其中AUTHOR_ID在意見表= 1。

我試着這樣做,但它給了我關於子查詢返回的多個項目的錯誤:

delete from news_items where comment_id = 
(select comment_id from comments where author_id = 1) 

回答

5
delete from news_items where comment_id IN 
(select comment_id from comments where author_id = 1) 
             ^^ 
             IN 
2

試試這個

delete from news_items where comment_id in 
(select comment_id from comments where author_id = 1)