SQL Server 2008 R2 - 查找select语句之间的差异

时间:2016-05-15 17:05:14

标签: sql-server-2008-r2 not-exists notin

如何根据同一个表找到两个select语句之间的差异?例如:

SELECT ID
FROM Table as TableA
WHERE Date = '2016-04-30'

根据上面的选择声明,我想找到所有不存在的ID:

SELECT ID
FROM Table as TableB
WHERE Date = '2016-03-31'

2 个答案:

答案 0 :(得分:1)

{{1}}

答案 1 :(得分:1)

早期的答案很聪明。这是一种简单的方法。

Select ID from Table
where Date = '2016-04-30' 
and ID not in (select ID from Table where Date = '2016-03-31')