我想更改 table_one 中列 this 的值,其中 this = 1 和 id 值该行存在于 table_two 列 other_id
中的任何位置所以我正在使用这个查询:
UPDATE table_one SET this='0' WHERE this='1' AND table_one.id IN (SELECT other_id FROM table_two);
查询花了几个小时还没有完成,所以我想知道是否有办法更快地完成查询。
如果重要的话,table_one.id 和 table_two.other_id 都具有唯一值。
table_one 有 55 万行
table_two 有 30k 行
MySQL 5.0.22
最佳答案
尝试使用 EXISTS 而不是 IN
关于sql - 优化 MySQL 查询(更新 + 子查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3380989/