如何使用mysql中同一个表的结果更新行?
像这样......UPDATE `ps_product_lang`
SET `description` = (
SELECT `description`
FROM `ps_product_lang`
WHERE `id_product` = 300003)
WHERE `id_product` = 300003
我收到了错误
#1093 - 您无法指定目标表'ps_product_lang'进行更新 在FROM子句中
答案 0 :(得分:0)
使用JOIN:
UPDATE ps_product_lang AS p1
CROSS JOIN ps_product_lang AS p2
SET p1.description = p2.description
WHERE p1.id_product = 300003
AND p2.id_product = 300003
你真的想在源和目的地使用相同的id_product
吗?那不会做任何事情。
答案 1 :(得分:0)
这就是答案:
UPDATE ps_product_lang AS p1
CROSS JOIN ps_product_lang AS p2
SET p1.description = p2.description
WHERE p1.id_product = 300003 and p1.`id_lang` =3
AND p2.id_product = 300003 and p2.`id_lang` =1
巴马 - 感谢! :)