比较两个表中的行值,如果行中的任何值不同,则返回

时间:2014-02-25 10:10:39

标签: tsql

如何比较两个表中的行,并且如果列中的至少一个值不同,则返回该行。

表A

No   Name   ID   Date       Profile  Status  Age    
1    John   213  12/2/2010   KDS      ONB    32
1    John   213  12/2/2011   KDS      ONB    23
2    John   213  12/2/2012   KDS      ONB    13
1    John   213  12/2/2013   KDS      ONB    14
2    John   213  12/2/2012   KDS      ONB    41

表B

No   Name   ID   Date       Profile  Status  Age    
1    John   213  12/2/2010   KDS      ONC    32
1    John   213  12/2/2011   KDS      ONB    23
2    John   213  12/2/2012   KDS      ONB    14
1    John   213  12/2/2013   KDS      ONB    14
2    John   213  12/2/2012   KDD      ONB    41

我应该在表B中获得以下行:

1    John   213  12/2/2010   KDS      ONC    32
2    John   213  12/2/2012   KDS      ONB    14
2    John   213  12/2/2012   KDD      ONB    41

1 个答案:

答案 0 :(得分:1)

select * from tableB except select * from tableA