簡體   English   中英

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

[英]Update table using another table and INNER JOIN

我在使用MYSQL updateinner join聯接時遇到問題。

我需要使用另一個表來連接屬性。

我的查詢:

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

錯誤信息 :

 #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

不確定FROMINNER JOIN可以在更新查詢中使用。 嘗試以下方法:

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

嘗試這個

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