这是我在我的数据库中的查询
UPDATE NewCustomer INNER JOIN ACTList ON NewCustomer.NewProvider<>ACTList.Provider SET NewCustomer.Status = "Denied Not Freemail";
如您所见,唯一应该更新的记录是 NewCustomer.Provider 不等于 ACTList.Provider 但它实际上正在更新所有字段的记录。
有人能告诉我这是为什么吗?
您的查询选择了所有行,因为每一行不等于 ActList 中的至少一行。您可以使用外部联接并检查空值。
UPDATE NewCustomer LEFT JOIN ACTList ON NewCustomer.NewProvider = ACTList.Provider SET NewCustomer.Status = "Denied Not Freemail"
WHERE (((ACTList.Provider) Is Null));
尝试:
UPDATE NewCustomer
SET NewCustomer.Status = "Denied Not Freemail"
FROM NewCustomer INNER JOIN ACTList
WHERE NewCustomer.NewProvider<>ACTList.Provider;
试一试(未经测试)。它基本上说WHERE NewCustomer.NewProvider NOT IN ()
,但更有效。
UPDATE NewCustomer
SET NewCustomer.Status = "Denied Not Freemail"
LEFT JOIN ACTList ON NewCustomer.NewProvider = ACTList.Provider
WHERE ACTList.Provider IS NULL