T-SQL:比较两个表 - 第二个表中不存在的记录 [英] T-SQL: Comparing Two Tables - Records that don't exist in second table
问题描述
如果 UNION ALL
是 T-SQL 中的 addition.减法的等价物是什么?
If UNION ALL
is an addition in T-SQL. What is the equivalent of subtraction?
例如,如果我有一个表 PEOPLE
和一个表 EMPLOYEES
.而且我知道如果我从 PEOPLE
中删除 EMPLOYEES
记录,我将留下我的公司 CONTRACTORS
.
For example, if I have a table PEOPLE
and a table EMPLOYEES
. And I know if I remove EMPLOYEES
records from PEOPLE
I will be left with my companies CONTRACTORS
.
是否有类似于 UNION ALL
的方法?一个我不必指定任何字段名称的地方?我问的原因是这只是一个假设的例子.我需要对许多不同的表执行多次此操作.假设 EMPLOYEES
和 PEOPLE
的 schema 是一样的.
Is there a way of doing this that is similar to UNION ALL
? One where I don't have to specify any field names? The reason I ask is this is just one hypothetical example. I need to do this several times to many different tables. Assume that the schema of EMPLOYEES
and PEOPLE
are the same.
推荐答案
不要使用 UNION,而是使用 EXCEPT, ( 或 INTERSECT 只获取两者中的记录)如
Instead of using UNION, use EXCEPT, ( or INTERSECT to get only records in both ) as described in
这篇关于T-SQL:比较两个表 - 第二个表中不存在的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!