gpt4 book ai didi

MySQL - 更新查询返回的表中的值?

转载 作者:行者123 更新时间:2023-11-29 06:32:05 26 4
gpt4 key购买 nike

我触发了这个查询,我连接两个表并输出两个表的一些列:

SELECT B.option_id, B.product_id, A.title, B.identifier 
FROM `catalog_product_option_title` A JOIN
`catalog_product_option` B
ON A.option_id = B.option_id
WHERE A.title = "Breite"

结果:

enter image description here

现在我需要在结果中的 identifier 列上的各个位置输入示例值 xyz。我会继续手动完成此操作。

如何利用 MySQL 的 update 语句来解决这个问题,而无需手动更改它?

我尝试过这样的:

UPDATE `catalog_product_option`
SET identifier = 'xyz'
WHERE option_id IN (
SELECT A.option_id
FROM `catalog_product_option_title` A
JOIN
`catalog_product_option` B
ON A.option_id = B.option_id
WHERE A.title = "Breite"
)

但是该查询的模拟返回这将更改 0 行。

更新

我调用了sql但没有模拟它,现在我得到了这个错误:

1093 - Table 'catalog_product_option' is specified twice, both as a target for 'UPDATE' and as a separate source for data

最佳答案

您可以将查询重写为 JOIN:

UPDATE `catalog_product_option` B
JOIN `catalog_product_option_title` A ON A.option_id = B.option_id
SET B.identifier = 'xyz' WHERE A.title = "Breite"

关于MySQL - 更新查询返回的表中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55686858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com