我有两个不同的表
在第一个(t1)
我有
Table [t1]
id Product_URL
Table [t2]
id Product_id Product_URL
我想UPDATE ALL
product_id字段(从t2开始)到第一个id
WHERE t1.product_url = t2.product_url
我可以在一个查询中执行此操作吗?
答案 0 :(得分:1)
UPDATE t2
JOIN (
SELECT t2_2.id, t1.id as new_id
FROM
t2 t2_2 JOIN
t1 ON t2_2.product_url = t1.product_url AND t2_2.product_id <> t1.id
ORDER BY t2_2.id
LIMIT 5000
) sub ON t2.id = sub.id
SET id = sub.new_id;
编辑:It looks like mutli-table updates do not play well with LIMIT
and ORDER BY
,但这是另一个完成同样事情的查询...