开发者

mySQL Quickly Delete Lots of Rows

I have two tables, I need all rows from the first that don't appear in the second.

The tables can be destroyed as they're dumps from other tables.

First table has ~57million rows开发者_如何学Python. Second table has ~10million rows.

Both of these queries are taking forever for obvious reasons, please help me do this quicker.

SELECT *
FROM db.first
WHERE id NOT IN (SELECT id FROM db.second)
DELETE FROM db.first
WHERE id IN (SELECT id FROM db.second)

Edit: I don't need any records from the second table, I only need rows that appear in the first table that don't appear in the second table.


It would probably be a lot quicker using joins:

select one.*
from db.first one
left join db.second two on one.id = two.id
where two.id is null

and the delete:

delete first
from first 
join second on first.id = second.id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜