我正在尝试替换单个表中的列数据。
有表'catalog_category_product':
'position','old_position','category_id','product_id'。
仅当category_id = 9时,我才想将“ old_position”替换为“ position” 这是我的查询:
UPDATE catalog_category_product
SET catalog_category_product.old_position =
(
select position
FROM (select * from catalog_category_product) AS m2
WHERE category_id = 110
)
WHERE category_id = 9`
答案 0 :(得分:0)
尝试一下:
Update catalog_category_product as c1, catalog_category_product as c2 set c1.old_position = c2.position where c2.category_id = 110 and c1.category_id = 9
答案 1 :(得分:0)
UPDATE catalog_category_product AS t1 INNER JOIN catalog_category_product AS t2
ON t1.product_id = t2.product_id
SET t1.old_position = t2.position
WHERE t1.category_id = {{$parentCategory}} AND t2.category_id = {{$childCategory}
对我有用