简体   繁体   English

MySQL 更新内连接

[英]MySQL Update INNER JOIN

I tried to update a column in a specific table which has a parent table.我试图更新具有父表的特定表中的列。 The table is gradings and the column in this table whose value I want to update is sy_id.该表是gradings ,该表中我要更新其值的列是sy_id.

The other table school_years has column sy_id and sy_dates which having a value.另一个表school_years sy_idsy_dates列有一个值。 2018 -2019, 2019 - 2020....

I want to update the column sy_id in gradings but I have no idea how to solve the error.我想更新gradings sy_id列,但我不知道如何解决该错误。

UPDATE gradings
INNER JOIN school_years
ON gradings.sy_id = school_years.sy_dates
INNER JOIN students
ON gradings.student_id = students.id
SET gradings.sy_id = '2017 - 2018'
WHERE students.id = 1;

Any thoughts?有什么想法吗?

Assuming that you are not joining on the wrong columns, this should work fine:假设您没有加入错误的列,这应该可以正常工作:

update gradings g,
    school_years sy,
    students s 
set 
    g.sy_id = '2017 - 2018'
where
    g.student_id = s.id
        and g.sy_id = sy.sy_dates
        and s.id = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM