1

我想一次删除多条记录。

我有两张桌子,一张包含

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

我想从评论表中 author_id = 1 的 news_comments 中删除所有记录。

我试过这样做,但它给了我一个关于返回多个项目的子查询的错误:

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

2 回答 2

5
delete from news_items where comment_id IN 
(select comment_id from comments where author_id = 1)
                                        ^^
                                        IN
于 2012-04-03T20:11:17.530 回答
2

尝试这个

delete from news_items where comment_id in 
(select comment_id from comments where author_id = 1)
于 2012-04-03T20:11:42.413 回答