[英]batch delete records in database table
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.我想删除评论表中 author_id = 1 的 news_comments 中的所有记录。
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)
delete from news_items where comment_id IN
(select comment_id from comments where author_id = 1)
^^
IN
try this试试这个
delete from news_items where comment_id in
(select comment_id from comments where author_id = 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.