[英]datetime comparison between two columns of two different tables in sql Server
i have 2 tables who includes thes sames colums but the differentes data.我有 2 个包含相同列但不同数据的表。
TOOLS DATE
----------- ----------------------
A10MA17 2021-09-25 05:14:16.000
x10UA50 2021-09-25 05:06:50.000
LU0NV03 2021-09-25 05:04:49.000
NU0MAK8 2021-09-25 05:02:22.000
252WA17 2021-09-25 05:15:12.000
I would like to select the data which is in table (A) but which is not in table (B) at a later date, that is to say the program must select a data in the tables (A) and go see if it does not exist in the tables B at a later date.我想稍后选择表(A)中但不在表(B)中的数据,也就是说程序必须选择表(A)中的数据并查看它是否存在以后不存在于表 B 中。
i use this request but I don't know how to add the filter on the date我使用此请求,但我不知道如何在日期添加过滤器
SELECT TOOLS FROM A WHERE A NOT IN (SELECT TOOLS FROM B)
thank's for help感谢帮助
As I mentioned in the comment, I would suggest using a NOT EXISTS
with a correlated subquery:正如我在评论中提到的,我建议将NOT EXISTS
与相关子查询一起使用:
SELECT A.Tools
FROM dbo.A
WHERE NOT EXISTS (SELECT 1
FROM dbo.B
WHERE B.Tools = A.Tools
AND B.[Date] > A.[Date]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.