本文介绍了如何从2个数据表中仅获取不匹配的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 hai朋友我有一个概念,,, i有2个数据表dt1,dt2 dt1包含 A B C D 和dt2 包含 A B C D E 我想要 只有E 如何获得plz帮助hai freinds i have a prob ,,,i have 2 datatables dt1,dt2dt1 contains ABCDand dt2 contain ABCDEI want only Ehow to get plz help推荐答案 SELECT *FROM dt2WHERE field1 NOT IN (SELECT field1 FROM dt1) 这将为您提供表2中不在表1中的所有值。This will give you all values from table 2 that are not in table 1. With CTE (C1,C2) As ( SELECT T1.Col1 As C1,T2.Col1 As C2 FROM Table_2 T2 full join Table_1 T1 On T2.Col1=T1.Col1 ) Select ISNULL(C1,C2) As Col1 from CTE where C1 Is Null Or C2 Is Null Order By ISNULL(C1,C2) 结果 ResultsCol1EF b $ b 创建测试数据 Create test dataCREATE TABLE [dbo].[Table_1]( [col1] [nchar](10) NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[Table_2]( [col1] [nchar](10) NULL) ON [PRIMARY]GOinsert into table_1 values ('A');insert into table_1 values ('B');insert into table_1 values ('C');insert into table_1 values ('D');insert into table_1 values ('F');insert into table_2 values ('A');insert into table_2 values ('B');insert into table_2 values ('C');insert into table_2 values ('D');insert into table_2 values ('E'); 这篇关于如何从2个数据表中仅获取不匹配的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 21:41