我必须连接两个表并从一个表中删除第二个表中不存在的行。我正在尝试下面的查询。我应该只删除 7 条记录,但它会删除整个 PERSONS 表。
DELETE PERSONS.*
FROM PERSONS
WHERE EXISTS (
SELECT PERSONS.[IR NUMBER],
PERSONS.[Last Name],
PERSONS.[First Name],
PERSONS.DOB,
PERSONS.[Name Type]
FROM 1 tblPERSON
RIGHT JOIN PERSONS
ON (
iif(isnull([1tblPERSON].DOB) = true, "01/01/9999", [1tblPERSON].DOB) =
iif(isnull(PERSONS.DOB) = true, "01/01/9999", PERSONS.DOB)
)
AND ([1tblPERSON].FIRSTNAME = PERSONS.[First Name])
AND ([1tblPERSON].LASTNAME = PERSONS.[Last Name])
AND ([1tblPERSON].NAMETYPELIT = PERSONS.[Name Type])
AND ([1tblPERSON].INCINMBR = PERSONS.[IR Number])
WHERE (
(
(PERSONS.[IR Number]) IN (
SELECT [QryIncinmbrsForDelete] ! [INCINMBR]
FROM [QryIncinmbrsForDelete]
)
)
AND (
(PERSONS.[Last Name]) NOT IN (
"UNKNOWN",
"UNK",
"UKNOWN"
)
)
AND ((IsNull([1tblPERSON].[INCINMBR])) = True)
)
) = true;
编辑:
在此示例中... 1, DOE, JOHN, 1/1/1960, Cust 将被删除
1人:
INCINMBR Last Name First Name DOB NameType
1 DOE JON 1/1/1960 Cust
1 SMITH JOHN 2/2/1965 Emp
1 JONES JAY 3/3/1965 Cust
人员:
INCINMBR Last Name First Name DOB NameType
1 DOE JON 1/1/1960 Cust
1 SMITH JOHN 2/2/1965 Emp
1 JONES JAY 3/3/1965 Cust
1 DOE JOHN 1/1/1960 Cust