-1

My below MySQL is giving error.

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

However, select works fine.

select P.id, a.name
FROM POSTS AS P INNER JOIN AUTHORS AS A
ON P.author_id = A.id;

I am not able to figure out what am I doing wrong, any help?

2
  • 1
    Your update looks correct for TSql. This link shows a different syntax for MySql - mysqltutorial.org/mysql-update-join Commented Jan 24, 2018 at 15:52
  • the SET needs to goes after the INNER JOIN Commented Jan 24, 2018 at 15:53

2 Answers 2

1

For MySql, you'll need to code the JOIN first, and then the SET statement:

UPDATE POSTS INNER JOIN AUTHORS ON POSTS.author_id = AUTHOR.id
SET POSTS.author_name = AUTHOR.name 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it worked. I got it from the comment by Joe C. I will accept your answer when SO will allow me after 8 mins.
0
UPDATE POSTS 
INNER JOIN AUTHORS ON POSTS.author_id = AUTHORS.id;
SET POSTS.author_name = AUTHORS.name 

1 Comment

This answer lacks an explanation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.