我有两个问题。我需要生成第三个查询,删除所有在其中找到Child Name的行。因此,如果[Child Not Seen_Pull]。[Child_Name]匹配[Child Seen_Pull]。[Child_Name],则在新查询中将删除符合条件(匹配名称)的行。我是Access的新手,所以我不确定如何在Access SQL中编写它。
* *查询1 [Child 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];
答案 0 :(得分:0)
这很简单。保存生成ID的两个查询。然后创建一个新的DELETE查询。将a和b替换为您的表名,或者更好的是,右键单击每个表,将别名更改为a或b,然后单击“确定”。
DELETE a.*
FROM a JOIN b ON a.ID = b.ID;
答案 1 :(得分: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查询之前,请务必制作数据的备份副本,以防万一它没有按照您的意图行事。