我希望我能足够清楚地解释这一点:在我们的 Magento 数据库中,我有以下两个查询,我需要以某种方式组合起来(我是 SQL 新手):
update catalog_product_entity_text
set `value` = CONCAT('', `value`)
where entity_id in (select product_id from catalog_category_product where category_id = 975)
and attribute_id = 57;
select `value` from catalog_product_entity_text
where entity_id in (select product_id from catalog_category_product where category_id = 571)
and attribute_id = 551;
第一个查询中 CONCAT 函数中的空白值需要包含第二个查询中与循环中当前的entity_id 相对应的值。
我该如何实现这一目标?非常感谢。
更新:我正在阅读连接,看起来好像同一个表上的左外连接就是这样,尽管我仍然不清楚正确的语法和用法。
这是一个根本无法通过的草稿:
select `value` from catalog_product_entity_text
as mobile_description
where attribute_id = 551
and entity_id in (select product_id
from catalog_category_product
where category_id = 571)
join on entity_id;
我该如何改进才能使其有效?
我正在尝试连接 attribute_id = 57 和 attribute_id = 551 的行,从每个行中获取具有相同entity_id 的 value
列,以便我可以更新 value
包含 attribute_id = 57 的行的值,以包含 attribute_id = 551 的相应记录的值。
最佳答案
我想说类似的东西应该有效。当然要先备份数据库。这是纯粹的 SQL 问题。
update catalog_product_entity_text
set `value` = CONCAT((select `value` from catalog_product_entity_text
where entity_id in (select product_id from catalog_category_product where category_id = 571) and attribute_id = 551), `value`)
where entity_id in (select product_id from catalog_category_product where category_id = 975)
and attribute_id = 57;
如果它不起作用,请告诉我,但您可以快速查看 this answer
关于mysql - 在 MySQL 中,如何更新一批字段以将它们的值与同一个表中对应于entity_id的值连接起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47772897/