简体   繁体   English

使用另一个表和INNER JOIN更新表

[英]Update table using another table and INNER JOIN

I get an issue using update and inner join with MYSQL. 我在使用MYSQL updateinner join联接时遇到问题。

I need to concat properties using another table. 我需要使用另一个表来连接属性。

My query : 我的查询:

update cfc_registration
 set teams = concat(r.teams, " - ", u.firstname, " ", u.lastname)
 from cfc_registration as r
 inner join cfc_user as u
 on r.cfcUserId = u.id
 where r.cfcTournamentId = 5

Error message : 错误信息 :

 #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 cfc_registration as r inner join cfc_user as u on r.cfcUserId = u.id whe' at line 3

Not sure FROM and INNER JOIN can be used in an update query. 不确定FROMINNER JOIN可以在更新查询中使用。 Try this instead: 尝试以下方法:

update cfc_registration r, cfc_user u
set teams = concat(r.teams, " - ", u.firstname, " ", u.lastname)
where r.cfcTournamentId = 5 and r.cfcUserId = u.id

Try this 尝试这个

UPDATE cfc_registration as r
inner join cfc_user as u
on r.cfcUserId = u.id
and r.cfcTournamentId = 5 set teams = concat(r.teams, " - ", u.firstname, " ",    u.lastname)

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

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