我需要一些帮助来快速更新我在MySQL中的表
Table 1
id | value
1 0
2 0
3 0 ...
Table 2
t1_id | t2_id
1 2
1 3
3 5 ...表1中有大约150,000行,表2中有大约130万行。当表2中存在t1.id时,我需要设置t1.value =1。
update table1 t1, table2 t2
set value = 1
where t1.id = t2.id;如果没有一些不同的参数,它将对每个id执行多次操作,从而使更新所有t1行的速度变慢。
任何帮助都会被欣然接受。
发布于 2017-07-10 22:15:27
下面是什么:
UPDATE t1
SET t1.value = 1
FROM table_t1 t1
WHERE EXISTS (SELECT 1
FROM table_t2 t2
WHERE t2.id = t1.id
)发布于 2017-07-10 22:32:09
下面是什么:
update table1
set value=1
from table2
where table1.id=table2.t1_idhttps://stackoverflow.com/questions/45014336
复制相似问题