我有表report_business_likes
与相关领域:如何根据mySql中的其他表更新字段值?
id, facebook_id, created_at, some_info
-- ----------- ----------- ----------
1 123456789 '2013-12-23' blabla
我有一个名为businesses
,接着结构的其他表:
id, fb_id, data
-- ----- ----
33 123456789 xxx
我想在report_business_likes
场facebook_id
与id
从表businesses
更换。
在我的情况下,结果应该是:
id, facebook_id, created_at, some_info
-- ----------- ----------- ----------
1 33 '2013-12-23' blabla
正如你可以看到我更换123456789
与33
。
我该如何做到这一点?
我想:
UPDATE `report_business_likes` SET facebook_id = BZ.id from
(select id from `businesses` where fb_id = 123456789) as BZ,
where facebook_id = 123456789 AND date(created_at) = '2013-12-23';
,但得到语法错误:
[SQL] /*SELECT * FROM `report_business_likes` where facebook_id = 123456789 AND date(created_at) = '2013-12-23';*/
UPDATE `report_business_likes` SET facebook_id = BZ from
(select id from `businesses` where fb_id = 123456789) as BZ,
where facebook_id = 123456789AND date(created_at) = '2013-12-23';
[Err] 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 'from
(select id from `businesses` where fb_id = 123456789) as BZ,' at line 3
请帮帮忙,
表和列名中的报价。 – Sergi
发布错误信息请 – Barranka
@Barranka我发布了一个错误,谢谢 – snaggs