我尝试在执行两个内部联接后更新一个数据库中的表中的列,其中一个是与来自同一服务器上另一个数据库的表。我试图在这里遵循这个解决方案: Update Query with INNER JOIN between tables in 2 different databases on 1 server
这对我不起作用。它给了我:你的语法在 s_u 附近有错误
这是我的尝试(更新:我删除了代码卫生。所以这是我现在运行的确切代码):
UPDATE s_u
SET s_u.bill_address_id=spree_billing.id
FROM spree_users AS s_u
INNER JOIN magento.customer_entity_int AS default_billing
ON default_billing.entity_id=s_u.magento_id
AND default_billing.attribute_id=14
INNER JOIN spree_addresses AS spree_billing
ON spree_billing.magento_address_id=default_billing.value;
最佳答案
你提到了一个叫做 spree_billing 的东西,它没有出现在你的声明中的任何地方。你需要修复它。问题可能出在这里:
UPDATE s_u
SET s_u.bill_address_id=billing.id -- modify to billing, as it is what third_table's alias is called
FROM some_table AS s_u
INNER JOIN magento.another_table AS default_billing
ON default_billing.entity_id=s_u.magento_id
AND default_billing.attribute_id=14
INNER JOIN third_table AS billing
ON billing.magento_address_id=default_billing.value;
关于mysql - 使用同一服务器上两个数据库之间的 2 个内部连接更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20109722/