【问题标题】:Update table using another table and INNER JOIN使用另一个表和 INNER JOIN 更新表
【发布时间】:2019-02-02 16:54:33
【问题描述】:

我在 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

【问题讨论】:

  • 先试一试-> ..SET r.teams = concat(r.teams, u.firstname, u.lastname) as ConcatString
  • 使用set r. teams = concat(r.teams, " - ", u.firstname, " ", u.lastname) as ConcatString,我收到相同的错误消息。
  • 好吧,先简单试试,不用 concat ->.. set r.teams = u.firstname.. 如果可行,那么试试不带双引号的 concat。
  • “更新自”..?

标签: mysql sql inner-join


【解决方案1】:

不确定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

【讨论】:

  • 嘿,我不想粗鲁,但非常轻微的帖子编辑会被拒绝,
【解决方案2】:

试试这个

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 2019-12-28
    相关资源
    最近更新 更多