0

I have 2 tables with same columns :

ID    A    B    C
-------------------

I'm using the command Except to have the difference between these 2 tables. It's almost perfect ... but look this case :

Table 1 :

ID    A    B    C
-------------------
1     1    1    1
1     2    2    2
1     1    1    1

Table 2 :

ID    A    B    C
-------------------
1     1    1    1
1     2    2    2
1     3    3    3

Except returns 0 row because the row 1 1 1 1 is already present in these table even if he is present in a different number ... here is the problem.

I need to have

1   1   1   1

as result ... as many times as the row doesn't appear in the second table.

Thanks in advance

4

1 回答 1

5
Select id,a,b,c from 
(
Select *, Row_Number() Over (Partition By id,a,b,c order by id,a,b,c) as Row
from t1
Except
Select *, Row_Number() Over (Partition By id,a,b,c order by id,a,b,c) as Tow
from t2
  ) t

SQL 小提琴演示

于 2013-07-30T09:36:35.717 回答