SQL not in

tab1: a b
tab2: c d
如何查询 除a=c且b=d 的数据?要同时满足才排除,满足一个还是显示
换个表述:
tab1: a b
tab2: c d
排除a&b=c&d 的查询
两位的答案都不对.譬如
te100:
002 1
001 1
001 2
te101:
001 1
002 2
select te100.* from te100,te101 where te100.a<>te101.c or te100.b<.te101.d
的结果是
001 1
002 1
002 1
001 2
要的结果是
002 1
001 2

大体的思想是select o.a ,o.b, p.c, p.d from tab1 o,tab2 p where not ((o.a=p.c) and (o.b=p.d))
或者按等价来处理
select o.a ,o.b, p.c, p.d from tab1 o,tab2 p where o.a<>p.c or o.b<>p.d
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-06-23
除a=c且b=d 不就等价与 A<>c或b<>d??
select h.*,g.* from tab2 h,tab2 g where h.a<>g.c or h.b<>g.d