SQL语句来比较两个查询并仅提取未输入的记录

SQL语句来比较两个查询并仅提取未输入的记录,sql,ms-access,Sql,Ms Access,编辑:请再看一遍 `qryHistoryTimeLog` / `qryHistoryAppt` 34 , 03/07/17 , 170 / 34 , 01/13/17 , Checked Out and Complete 34 , 03/28/17 , 125 / 34 , 02/09/17 , Checked Out and Complete 34 , 04/28/17 , 140 / 34 , 03/07/17 , Checked Out and Comple

编辑:请再看一遍

`qryHistoryTimeLog`   /   `qryHistoryAppt`
34 , 03/07/17 , 170   /   34 , 01/13/17 , Checked Out and Complete
34 , 03/28/17 , 125   /   34 , 02/09/17 , Checked Out and Complete
34 , 04/28/17 , 140   /   34 , 03/07/17 , Checked Out and Complete
34 , 05/19/17 ,  85   /   34 , 03/28/17 , Checked Out and Complete
34 , 08/05/17 ,  75   /   34 , 04/28/17 , Checked Out and Complete
34 , 08/24/17 ,  65   /   34 , 05/19/17 , Checked Out and Complete
                      /   34 , 06/09/17 , Checked Out and Complete
                      /   34 , 08/05/17 , Checked Out and Complete
                      /   34 , 08/24/17 , Checked Out and Complete
查询
qryHistoryAppt
正在从软件的数据库表中提取客户34的所有预约,这些预约都是“签出并完成”的

查询
qryHistoryTimeLog
正在从我的客户预约输入信息表中提取

我正在查找已签出并完成的约会日期,但尚未输入我的
tblTimeLog
,因此我知道需要提取和输入哪些约会卡

`qryTesting`
34 , 01/13/17
34 , 02/09/17
34 , 06/09/17
我还应该补充一点,我正在通过这个新的查询传递客户号。这样,当我运行查询时,我可以输入我正在寻找的客户的约会

答复:

SELECT DISTINCT qryHistoryAppt.petId, 
                qryHistoryAppt.petName, 
                qryHistoryAppt.cstLName, 
                qryHistoryAppt.aptDate
FROM qryHistoryAppt LEFT JOIN qryHistoryTimeLog ON 
    (qryHistoryAppt.petId = qryHistoryTimeLog.PetID) AND 
    (qryHistoryAppt.aptDate = qryHistoryTimeLog.ApptDate)
WHERE (((qryHistoryAppt.petId)=[]) AND
       ((qryHistoryTimeLog.ApptDate) Is Null));

只需在petId和ApptDate上左连接
。现在你只和佩蒂德比赛


将其更改为
左连接
,然后
其中[qryHistoryTimeLog].[ApptDate]为空
通过
删除
分组,并且
不查找空值。比较软件方面没有输入tblTimeLog的日期。可能是@WEI_DBA的重复,请您再看看Where语句是否仍然正常工作。软件端的所有日期都不会输入tblTimeLog。我只想看看那张桌子上少了的日期。你能不能重新看看这个太棒了!!荣誉
SELECT qryHistoryAppt.petId, 
         qryHistoryAppt.petName, 
         qryHistoryAppt.aptDate
FROM qryHistoryAppt LEFT JOIN qryHistoryTimeLog ON qryHistoryAppt.petId = qryHistoryTimeLog.PetID
WHERE qryHistoryTimeLog.PetID is null
GROUP BY qryHistoryAppt.petId, qryHistoryAppt.petName, qryHistoryAppt.aptDate
HAVING (((qryHistoryAppt.petId)=[]))
ORDER BY qryHistoryAppt.aptDate DESC;
SELECT DISTINCT h.petId, h.aptDate
FROM qryHistoryAppt h
LEFT JOIN qryHistoryTimeLog l 
   ON h.petId = l.PetID AND h.aptDate = l.ApptDate
WHERE (((l.PetID) IS NULL));