多行更新mysql

hmtdttj4  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(336)

我正在尝试替换单个表中的列数据。
有一张“目录\类别\产品”表:
“位置”、“旧位置”、“类别标识”、“产品标识”。
仅当category\u id=9时,我想将“old\u 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`
yb3bgrhw

yb3bgrhw1#

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}

它对我有用

8yoxcaq7

8yoxcaq72#

试试这个:

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

相关问题