What's wrong with my MySQL statement?

好久不见. 提交于 2019-12-25 02:44:37

问题


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


回答1:


Try:

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



回答2:


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;


来源:https://stackoverflow.com/questions/1934938/whats-wrong-with-my-mysql-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!