我想用另一个表中的数据更新mySql中的表。
我有两个表“ people”和“ business”。人员表通过称为“ business_id”的列链接到业务表。
必要的表结构,主键带有星号(表:列):人员: business_id, sort_order,email商业:* business_id,email
我想用人员表中的电子邮件更新业务表电子邮件列,如下所示(我知道我在这里遗漏了一些内容):
UPDATE business b SET email = (SELECT email from People p where p.business_id = b.business_id AND sort_order = '1') WHERE b.email = '';
这有意义吗?可能吗?
UPDATE business b, people p SET b.email = p.email WHERE b.business_id = p.business_id AND p.sort_order = '1' AND b.email = ''