UPDATE table1 SET announcer = ( SELECT memberid
FROM ( table1
JOIN users ON table2.username = table1.announcer
) AS a
WHERE a.username = table1.announcer )
#1064 - 您的SQL语法出错;检查手册 对应于您的MySQL服务器 用于正确语法的版本 靠近'一个地方 a.username = table1.announcer)” 在第1行
答案 0 :(得分:1)
尝试:
UPDATE announcements a
SET announcer =
(SELECT memberid
FROM users u
WHERE u.username = a.announcer)
答案 1 :(得分:1)
您也可以在UPDATE中进行JOIN
UPDATE announcements JOIN users
SET announcements.announcer=users.memberid
WHERE announcements.username=users.username;
注意:出于安全原因(直到你确定的播音员被复制过来)我会创建一个新专栏,比如播音员新的
UPDATE announcements JOIN users
SET announcements.announcerNew=users.memberid
WHERE announcements.username=users.username;