多行更新mysql

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

我正在尝试替换单个表中的列数据。
有一张“目录\类别\产品”表:
“位置”、“旧位置”、“类别标识”、“产品标识”。
仅当category\u id=9时,我想将“old\u position”替换为“position”:

  1. UPDATE catalog_category_product
  2. SET catalog_category_product.old_position =
  3. (
  4. select position
  5. FROM (select * from catalog_category_product) AS m2
  6. WHERE category_id = 110
  7. )
  8. WHERE category_id = 9`
yb3bgrhw

yb3bgrhw1#

  1. UPDATE catalog_category_product AS t1 INNER JOIN catalog_category_product AS t2
  2. ON t1.product_id = t2.product_id
  3. SET t1.old_position = t2.position
  4. WHERE t1.category_id = {{$parentCategory}} AND t2.category_id = {{$childCategory}

它对我有用

8yoxcaq7

8yoxcaq72#

试试这个:

  1. 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

相关问题