x*g 发帖数: 689 | 1 问一个新手问题,如何根据多个列找不match的记录?
Table T1, column C1, C2, C3
Table T2, column C1, C2, C4
用INNER JOIN可以找到T1里面满足条件
T1.C1=T2.C1 AND T1.C2=T2.C2的记录。
我的问题是如何选出在T1里面不满足
T1.C1=T2.C1 AND T1.C2=T2.C2的记录?
谢谢 | c**t 发帖数: 2744 | 2 select C1, C2, C3 from T1
minus
select C1, C2, C3 from T2
vise versa
【在 x*g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 问一个新手问题,如何根据多个列找不match的记录? : Table T1, column C1, C2, C3 : Table T2, column C1, C2, C4 : 用INNER JOIN可以找到T1里面满足条件 : T1.C1=T2.C1 AND T1.C2=T2.C2的记录。 : 我的问题是如何选出在T1里面不满足 : T1.C1=T2.C1 AND T1.C2=T2.C2的记录? : 谢谢
| x*g 发帖数: 689 | 3 thanks for the reply.
I am using ms sql which I think doesn't have minus.
also the columns in T1 and T2 are not exact same.
【在 c**t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : select C1, C2, C3 from T1 : minus : select C1, C2, C3 from T2 : vise versa
| k***e 发帖数: 7933 | 4 ms sql 2005 has 'except'
【在 x*g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : thanks for the reply. : I am using ms sql which I think doesn't have minus. : also the columns in T1 and T2 are not exact same.
| I*****y 发帖数: 602 | 5 Left join应该可以。
select T1.* from T1
left join T2 on T1.c1=T2.c1 and ...
where T2.C1 is null
【在 x*g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 问一个新手问题,如何根据多个列找不match的记录? : Table T1, column C1, C2, C3 : Table T2, column C1, C2, C4 : 用INNER JOIN可以找到T1里面满足条件 : T1.C1=T2.C1 AND T1.C2=T2.C2的记录。 : 我的问题是如何选出在T1里面不满足 : T1.C1=T2.C1 AND T1.C2=T2.C2的记录? : 谢谢
| J*******n 发帖数: 2901 | 6
同楼上
不过应该
where T2.C4 is null吧
【在 x*g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 问一个新手问题,如何根据多个列找不match的记录? : Table T1, column C1, C2, C3 : Table T2, column C1, C2, C4 : 用INNER JOIN可以找到T1里面满足条件 : T1.C1=T2.C1 AND T1.C2=T2.C2的记录。 : 我的问题是如何选出在T1里面不满足 : T1.C1=T2.C1 AND T1.C2=T2.C2的记录? : 谢谢
|
|