【问题标题】:Error received on join update, incorrect syntax加入更新时收到错误,语法不正确
【发布时间】:2015-03-19 18:19:25
【问题描述】:

我在 MySQL 中收到以下 SQL 错误,我不确定原因。我是 MySQL 新手。

UPDATE I
SET I.user_comments = DD.value
FROM
redcap_user_information I
    JOIN redcap_data D ON D.value = I.user_email AND D.project_id = 439 AND D.field_name = 'email'
    JOIN redcap_data DD ON DD.record = D.record AND DD.project_id = 439 AND DD.field_name = 'irb'
WHERE
user_comments IS NULL
    AND allow_create_db = 1
    AND user_suspended_time IS NULL
ORDER BY I.user_email

错误是

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM
 redcap_user_information I
     JOIN redcap_data D ON D.value = I.use'

谁能解释一下?

【问题讨论】:

    标签: mysql join sql-update


    【解决方案1】:

    不确定联接部分的逻辑,但使用联接进行更新的正确语法如下

    update redcap_user_information I
    JOIN redcap_data D ON D.value = I.user_email AND D.project_id = 439 AND D.field_name = 'email'
    JOIN redcap_data DD ON DD.record = D.record AND DD.project_id = 439 AND DD.field_name = 'irb'
    set I.user_comments = DD.value
    WHERE
    user_comments IS NULL --- use the table alias name to access the column 
    AND allow_create_db = 1 --- use the table alias name to access the column
    AND user_suspended_time IS NULL --- use the table alias name to access the column
    

    【讨论】:

    • 哦,这与 MS SQL 不同 - UPDATE、SET、FROM、JOIN、WHERE。无论如何,谢谢你,那成功了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 2019-10-09
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多