我的MySQL下面给出了错误。
UPDATE P SET P.author_name = A.name
FROM POSTS AS P INNER JOIN AUTHORS AS A
ON P.author_id = A.id;
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 POSTS AS P INNER JOIN AUTHORS AS A
ON P.author_id = A.id' at line 2
但是,选择正常。
select P.id, a.name
FROM POSTS AS P INNER JOIN AUTHORS AS A
ON P.author_id = A.id;
我无法弄清楚我做错了什么,有什么帮助?
答案 0 :(得分:0)
UPDATE POSTS
INNER JOIN AUTHORS ON POSTS.author_id = AUTHORS.id;
SET POSTS.author_name = AUTHORS.name
答案 1 :(得分:0)
对于MySql,您需要首先对JOIN
进行编码,然后再对SET
语句进行编码:
UPDATE POSTS INNER JOIN AUTHORS ON POSTS.author_id = AUTHOR.id
SET POSTS.author_name = AUTHOR.name