从另一个表列值更新列

DIG*_*UAD 3 mysql mysql-5.7

我正在尝试从 comment_users 表 user_id 列值更新 comments 表上的 user_id 列,其中 comment_id 与 comments 表 id 列匹配。

评论用户表

id: 5 comment_id: 1, user_id: 20
Run Code Online (Sandbox Code Playgroud)


之前的评论表

id:1 user_id: NULL
Run Code Online (Sandbox Code Playgroud)

id: 1 user_id: 20
Run Code Online (Sandbox Code Playgroud)

我执行了下面的sql,但它不起作用。

UPDATE comments
  SET user_id = comment_users.user_id
  INNER JOIN comment_users ON comment_users.comment_id = comments.id
  WHERE comment_users.comment_id = comments.id


Mysql2::Error: 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 'INNER JOIN comment_users ON comment_users.comment_id = comment' at line 3:       UPDATE comments
      SET user_id = comment_users.user_id
      INNER JOIN comment_users ON comment_users.comment_id = comments.id
      WHERE comment_users.comment_id = comments.id
Run Code Online (Sandbox Code Playgroud)

我不知道出了什么问题。