sql - 如何在 MySQL 中使用 JOIN 更新多行?
问题描述
当“importer.sku”=“product_categories.product_reference”时,如何将“categories.name”设置为“importer.tag”?
解决方案
你可以尝试这样的事情:
UPDATE categories
SET name = importer.tag
FROM
categories
INNER JOIN product_categories ON categories.id = product_categories.category_id
INNER JOIN importer ON importer.sku = product_categories.product_reference;
请注意,这将更新类别表中的所有可能记录(可以与 product_categories 和导入器表连接)。如果您只需要更新类别中的特定记录,也可以使用 WHERE 子句。
编辑:
不是 categories.name 应该更新,而是 importer.tag...对不起...
UPDATE importer
SET tag = categories.name
FROM
importer
INNER JOIN product_categories ON product_categories.product_reference = importer.sku
INNER JOIN categories ON categories.id = product_categories.category_id;
编辑2:
作为 MS SQL Server 用户,我不知道 MySQL 对 UPDATE 查询使用的语法略有不同。快速浏览 MySQL 文档后,您可以尝试以下查询:
UPDATE
importer
INNER JOIN product_categories ON product_categories.product_reference = importer.sku
INNER JOIN categories ON categories.id = product_categories.category_id
SET
tag = categories.name;
推荐阅读
- ios - 如何对存储在字典中的元组内的数组进行排序
- spring - Oauth Client Credentials AccessToken 在哪里存储此令牌并再次访问
- javascript - 单击javascript后端中的按钮时运行什么代码
- python - 在 matplotlib 曲面绘图时,对象不能广播到单个形状
- mips - MIPS 架构:如果在执行 beq r1,r3,00 之类的操作时 r1 不等于 r3 会发生什么?
- javascript - 重定向 ReactJS
- wordpress - 如何在重力表单中添加额外的提交按钮?
- matrix - 如何在 APL 中找到矩阵中每一行的平均值?和最高的平均值?
- networking - 如何从不同网络上的另一台计算机访问 localhost?
- reactjs - 选择选项与 react-router BUG 反应