我希望使用另一个表中的数据更新空字段

时间:2012-04-04 18:27:25

标签: mysql-error-1064 sql-update

我使用SELECT COUNT(*)检查我的WHERE语句并获得了正确的更新次数,但是当我尝试UPDATE时,我在第3行遇到语法错误。

UPDATE scans AS s
SET s.sbjnum = d.sbjnum
JOIN details AS d on d.name = s.name
WHERE s.sbjnum =''

1 个答案:

答案 0 :(得分:1)

您必须拥有FROM才能拥有JOIN

UPDATE scans 
SET sbjnum = d.sbjnum 
FROM scans s
JOIN details AS d ON d.name = s.name 
WHERE s.sbjnum =''

根据MySQL手册,您可以这样写:

UPDATE scans AS s
JOIN details AS d ON d.name = s.name 
SET sbjnum = d.sbjnum 
WHERE s.sbjnum =''