我目前有两张桌子。它们都有一个account_number的主键
purchase_email (this_record,account_number,econtact_address)
PURCHASE-LEDGER (this_record,e_mail,account_number)
目前,purchase_email具有我希望转移到e_mail字段中当前为空的购买分类帐表的所有电子邮件地址。下面是我认为正确的查询,但是每次运行它时都会出现一个窗口,它是“purchase_email.econtact_address”的输入参数值以及purchase-ledger.email的另一个窗口。 我很困惑为什么它这样做,并尝试了许多不同的查询仍然没有失败。有人可以帮忙吗?
INSERT INTO [purchase-ledger] ( e_mail )
SELECT econtact_address
FROM purchase_email
WHERE purchase-ledger.account_number=purchase_email.account_number;
答案 0 :(得分:0)
您需要使用UPDATE语句,而不是INSERT
:
UPDATE [purchase-ledger]
INNER JOIN purchase_email
ON purchase_email.Account_number = [purchase-ledger].Account_number
SET e_mail = purchase_email.econtact_address;
答案 1 :(得分:0)
如果这是实际代码,而不是拼写错误,则WHERE子句中的表名需要括号,因为名称中有一个破折号。你有:
INSERT INTO [purchase-ledger] ( e_mail )
SELECT econtact_address
FROM purchase_email
WHERE purchase-ledger.account_number=purchase_email.account_number;
你需要:
INSERT INTO [purchase-ledger] ( e_mail )
SELECT econtact_address
FROM purchase_email
WHERE [purchase-ledger].account_number=purchase_email.account_number;