联合所有但只保留T-SQL中一张表中的重复项

我有两张我想合并的表。我只需要保留两个表之一的重复项。我试图找到它,但在任何地方都找不到。希望有人能帮忙。

例如:表_1:

ID 产品 数量
1 一种 10
2 10
3 C 10

回答

使用not exists

Select t1.*
from Table_1 t1
where not exists (select 1 from table_2 t2 where t2.id = t1.id)
Union All
Select t2.*
from Table_2 t2;


以上是联合所有但只保留T-SQL中一张表中的重复项的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>