批量删除数据库表中的记录

时间:2012-04-03 20:09:42

标签: sql oracle

我想一次删除多条记录。

我有两个表,一个包含

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)

2 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:2)

试试这个

delete from news_items where comment_id in 
(select comment_id from comments where author_id = 1)
相关问题