Question

UPDATE table1 SET announcer = ( SELECT memberid
FROM ( table1
JOIN users ON table2.username = table1.announcer
) AS a
WHERE a.username = table1.announcer )

#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 'a where a.username=table1.announcer)' at line 1

Was it helpful?

Solution

Try:

UPDATE announcements a
SET announcer =
(SELECT memberid
FROM users u
WHERE u.username = a.announcer)

OTHER TIPS

You can also do the JOIN in the UPDATE

UPDATE announcements JOIN users
SET announcements.announcer=users.memberid
WHERE announcements.username=users.username;

Note: For safty reasons (until your sure announcers get copied over right) I'd instead create a new column, say announcerNew then

UPDATE announcements JOIN users
SET announcements.announcerNew=users.memberid
WHERE announcements.username=users.username;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top