首页 > 解决方案 > 多行更新麻烦mysql

问题描述

我正在尝试替换单个表中的列数据。

有表'catalog_category_product':

'位置','旧位置','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`

标签: mysql

解决方案


尝试这个:

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

推荐阅读