如何从具有内部联接的选择中更新字段值?

时间:2013-04-17 01:18:39

标签: mysql sql database sql-update

我正在尝试使用带内连接的选择查询来更新mysql数据库中的字段值

我目前正在

1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第5行“AS cc WHERE cc.account_id = na.account_id”附近使用正确的语法

UPDATE accounts AS na
SET na.pdm_id = (
SELECT cp.person_id FROM `temp_accounts` AS ta INNER JOIN call_managment_system.accounts AS a ON ta.company_code = a.company_code
INNER JOIN contact_personal AS cp ON cp.name = ta.FSM AND contact_link = 'PDM' 
) 
WHERE a.account_id = na.account_id

如何修复此查询?我想更新名为pdm_id的字段,将其设置为等于cp.person_id

由于

1 个答案:

答案 0 :(得分:1)

UPDATE  accounts na
INNER JOIN call_managment_system.accounts a
ON      a.account_id = na.account_id
INNER JOIN temp_accounts ta 
ON     ta.company_code = a.company_code
INNER JOIN contact_personal cp 
ON cp.name = ta.FSM        
SET     na.pdm_id = cp.person_id
WHERE   contact_link = 'PDM'