mysql - 在 MySQL 中,如何更新一批字段以将它们的值与同一个表中对应于entity_id的值连接起来?

标签 mysql sql magento

我希望我能足够清楚地解释这一点:在我们的 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/

相关文章:

php - 如何使用PHP限制用户上传图片的大小

SQL 游标...您会捍卫任何用例?

sql - 使用 Tablediff 比较所有表

Magento 安全措施

sorting - 在分层导航中选择特定购物选项时设置默认排序方式

php - MySQL PHP 搜索使用一个输入来搜索多列

MySQL:无法通过 SSH 使用 TCP/IP 进行连接

php - Mysql 向此查询添加 AND 子句

sql - 更改表以将IDENTITY设置为off

wordpress - 什么是一个不需要数年时间就能掌握的全面电子商务平台?