简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM