可以简单地这样来看:
A:
ID SUBID NAME
--- -------------
11X
21Y
32null
===========
B:
SUBIDNAME
-------- -------
1 X
1 Y
2
null
如何把两表具有相同数据的A.ID给取出来?有没有简单一点的方法?
别告诉我说这样写...
where (a.subid=b.subid or (a.subid is null and b.subid is null))
and (a.name=b.name or (a.name is null and b.name is null))
where (a.subid=b.subid or (a.subid is null and b.subid is null))
and (a.name=b.name or (a.name is null and b.name is null))
改为:
where a.subid = b.subid and nvl(a.name,'0')=nvl(b.name,'0')
原帖由 caizhuoyi 于 2008-10-31 19:54 发表
where (a.subid=b.subid or (a.subid is null and b.subid is null))
and (a.name=b.name or (a.name is null and b.name is null))
改为:
where a.subid = b.subid and nvl(a.name,'0')=nvl(b.name,'0')
噢,我把这个给忘了。。
还有其他好注意没了?
原帖由 caizhuoyi 于 2008-10-31 19:54 发表
where (a.subid=b.subid or (a.subid is null and b.subid is null))
and (a.name=b.name or (a.name is null and b.name is null))
改为:
where a.subid = b.subid and nvl(a.name,'0')=nvl(b.name,'0')
如果采用这种方法,所有的列都需要判断一次,如果字段比较多,并且B表中数据也比较多的话,会很慢吧?