0

我有两个疑问。我需要生成第三个查询,该查询删除在两者中都找到 Child Name 的所有行。因此,如果 [Child Not Seen_Pull].[Child_Name] 与新查询中的 [Child Seen_Pull].[Child_Name] 匹配,则删除符合条件(匹配名称)的行。我是 Access 新手,所以我不确定如何在 Access SQL 中编写它。

* *查询 1 [Child Not Seen_Pull] **

SELECT [Child Not Seen_Clean].ID, [Child Not Seen_Clean].[Case ID], [Child Not Seen_Clean].Child_Name, [Child Not Seen_Clean].[Worker Site / Unit], [Child Not Seen_Clean].[Worker Name], [Child Not Seen_Clean].[Worker Role], [Child Not Seen_Clean].[Contact Date], [Child Not Seen_Clean].[Contact Method], [Child Not Seen_Clean].[Contact Result], [Child Not Seen_Clean].Focus, [Child Not Seen_Clean].Participant
FROM [Child Not Seen_Clean]
WHERE ((([Child Not Seen_Clean].[Contact Method])<>"Face To Face") AND (([Child Not Seen_Clean].Participant)<>"Yes")) OR ((([Child Not Seen_Clean].[Contact Method]) Is Null)) OR ((([Child Not Seen_Clean].[Contact Method])="Face to Face") AND (([Child Not Seen_Clean].[Contact Result])="Attempted")) OR ((([Child Not Seen_Clean].[Contact Method])="Face to Face") AND (([Child Not Seen_Clean].[Contact Result])="Contacted") AND (([Child Not Seen_Clean].Focus)="Yes") AND (([Child Not Seen_Clean].Participant)="No")) OR ((([Child Not Seen_Clean].[Contact Method])="Phone") AND (([Child Not Seen_Clean].[Contact Result])="Contacted") AND (([Child Not Seen_Clean].Focus)="Yes")) OR ((([Child Not Seen_Clean].[Contact Method])="Fax") AND (([Child Not Seen_Clean].[Contact Result])="Contacted") AND (([Child Not Seen_Clean].Focus)="Yes")) OR ((([Child Not Seen_Clean].[Contact Method])="Phone") AND (([Child Not Seen_Clean].[Contact Result])="Attempted") AND (([Child Not Seen_Clean].Focus)="Yes")) OR ((([Child Not Seen_Clean].[Contact Method])="Mail") AND (([Child Not Seen_Clean].[Contact Result])="Attempted"))
ORDER BY [Child Not Seen].[ID];

查询 2

SELECT [Child Not Seen_Clean].[ID], [Child Not Seen_Clean].[Case ID], [Child Not Seen_Clean].Child_Name, [Child Not Seen_Clean].[Worker Site / Unit], [Child Not Seen_Clean].[Worker Name], [Child Not Seen_Clean].[Worker Role], [Child Not Seen_Clean].[Contact Date], [Child Not Seen_Clean].[Contact Method], [Child Not Seen_Clean].[Contact Result], [Child Not Seen_Clean].Focus, [Child Not Seen_Clean].Participant
FROM [Child Not Seen_Clean]
WHERE ((([Child Not Seen_Clean].[Contact Method])="Face To Face") AND (([Child Not Seen_Clean].[Contact Result])<>"Attempted") AND (([Child Not Seen_Clean].Participant)="Yes"))
ORDER BY [Child Not Seen].[ID];
4

2 回答 2

0

如果我正确理解了您的要求,那么以下查询应该可以满足您的要求:

DELETE FROM [Child Not Seen_Clean]
WHERE ID IN
    (
        SELECT [Child Not Seen_Pull].ID
        FROM 
            [Child Not Seen_Pull]
            INNER JOIN
            [Child Seen_Pull]
                ON [Child Not Seen_Pull].Child_Name=[Child Seen_Pull].Child_Name
        UNION
        SELECT [Child Seen_Pull].ID
        FROM 
            [Child Seen_Pull]
            INNER JOIN
            [Child Not Seen_Pull]
                ON [Child Seen_Pull].Child_Name=[Child Not Seen_Pull].Child_Name
    )

与往常一样,请务必在尝试使用 DELETE 查询之前制作数据的备份副本,以防万一它不符合您的真正意图。

于 2013-06-23T11:41:15.397 回答
0

这是相当简单的。保存生成 ID 的两个查询。然后创建一个新的 DELETE 查询。将 a 和 b 替换为您的表名,或者更好的是,右键单击每个表,将别名更改为 a 或 b,然后单击确定。

DELETE a.*
FROM a JOIN b ON a.ID = b.ID;
于 2013-06-21T19:39:57.500 回答