错误代码:1064关于MySQL更新查询

时间:2015-08-28 05:21:58

标签: mysql database updates

Table: immunization                 
id  vac_id  vaccine_id
1   5       0
2   5       0
3   3       0
4   4       0
5   4       0

Table: vaccine
id  vac_id
8   1
9   2
10  3
11  4
12  5

我有两个表,现在我想通过匹配疫苗将疫苗表的id设置到免疫表的vaccine_id中.vac_id = immunization.vac_id

要做到这一点我使用了查询,但收到错误1064

UPDATE immunization
SET  immunization.vaccine_id = vaccine.id
FROM vaccine,immunization
WHERE  vaccine.vac_id = immunization.vac_id

1 个答案:

答案 0 :(得分:1)

UPDATE immunization i
join vaccine v
on i.vac_id=v.vac_id
SET  i.vaccine_id = v.id

设置到最后