MySQL,使用内部联接的更新查询无提示失败

时间:2017-05-11 18:09:41

标签: php mysql sql database

我有一个内部联接的MySQL查询更新不起作用,而类似的内部联接选择查询工作正常。

工作SELECT查询

SELECT fa.tax_rate, efa.entity_id
FROM water_civicrmv2.civicrm_financial_account as fa
    INNER JOIN water_civicrmv2.civicrm_entity_financial_account efa ON efa.financial_account_id = fa.id 
    INNER JOIN water_civicrmv2.civicrm_option_value cov ON cov.value = efa.account_relationship
    INNER JOIN water_civicrmv2.civicrm_option_group cog ON cog.id = cov.option_group_id
    WHERE efa.entity_table = 'civicrm_financial_type'
    AND cov.name = 'Sales Tax Account is'
    AND cog.name = 'account_relationship'
    AND fa.is_active = 1

UPDATE查询失败

 UPDATE water_civicrmv2.civicrm_financial_account as fa
    INNER JOIN water_civicrmv2.civicrm_entity_financial_account efa ON efa.financial_account_id = fa.id 
    INNER JOIN water_civicrmv2.civicrm_option_value cov ON cov.value = efa.account_relationship
    INNER JOIN water_civicrmv2.civicrm_option_group cog ON cog.id = cov.option_group_id
    SET fa.tax_rate = '123123' 
    WHERE efa.entity_table = 'civicrm_financial_type'
    AND cov.name = 'Sales Tax Account is'
    AND cog.name = 'account_relationship'
    AND fa.is_active = 1

我真的不知道为什么它会无声地失败,因为没有语法错误,没有任何反应。

1 个答案:

答案 0 :(得分:1)

更改您的更新SQL,以便UPDATE的对象只是单个表water_civicrmv2.civicrm_financial_account:

 UPDATE water_civicrmv2.civicrm_financial_account as fa
    SET fa.tax_rate = '123123' 
    WHERE fa.id = 
          (SELECT fa.id
             FROM water_civicrmv2.civicrm_entity_financial_account efa
             INNER JOIN water_civicrmv2.civicrm_option_value cov ON cov.value = efa.account_relationship
             INNER JOIN water_civicrmv2.civicrm_option_group cog ON cog.id = cov.option_group_id
             WHERE efa.financial_account_id = fa.id 
               AND efa.entity_table = 'civicrm_financial_type'
               AND cov.name = 'Sales Tax Account is'
               AND cog.name = 'account_relationship'
               AND fa.is_active = 1)