MySQL-内部联接不适用于更新语句

时间:2019-01-01 12:40:53

标签: mysql

我有下面的查询不起作用,我不知道为什么,因为它似乎可以与其他类似的查询一起使用。你能告诉我我哪里出问题了吗?

UPDATE `Student` 
SET Student.Half = 0
FROM `Student`
INNER JOIN `Year`
    on Student.GradYear = Year.GradYear
    and Year.UserID = 1

它应该将表和Half都更新为0,但是它带有错误消息 “#1064-您的SQL语法有误;请查看与您的MySQL服务器版本相对应的手册,以获取在Student.GradYear = Year上'FROM Student INNER JOIN Year附近使用的正确语法.GradYear和Ye'在第3行“

1 个答案:

答案 0 :(得分:2)

UPDATE [LOW_PRIORITY] [IGNORE] table_reference
    SET assignment_list
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

value:
    {expr | DEFAULT}

assignment:
    col_name = value

assignment_list:
    assignment [, assignment] ...

根据MySQL文档,您的语法本身是错误的 https://dev.mysql.com/doc/refman/8.0/en/update.html

UPDATE `Student` 
INNER JOIN `Year`
    on Student.GradYear = Year.GradYear
    and Year.UserID = 1
SET Student.Half = 0;

^这应该工作。