日期:2014-05-17  浏览次数:20401 次

基础问题求教
有两个select语句 ,我想把它们结合起来并去重请教
select *from reportA  where reportA.网元名称 not in (select reportB.网元名称 from reportB)

结果
a1 NULL NULL NULL NULL NULL NULL
a2 NULL NULL NULL NULL NULL NULL
另一个
select * from reportA where checksum(*) not in (select checksum(*) from reportB)

结果
3001-江南 GE 0 0 0 0 0
3016-江北4 E3/T3 0 0 0 0 0
a1     NULL NULL NULL NULL NULL NULL
a2     NULL NULL NULL NULL NULL NULL



我想得到
3001-江南 GE 0 0 0 0 0
3016-江北4 E3/T3 0 0 0 0 0


求教谢谢

------解决方案--------------------
引用:
直接用union是不可以的 无法去重

你这个有点误导啊,去重是要保留一条记录的,你的需求是有重复的数据都不保留

select * from (
select * from reportA  where reportA.网元名称 not in (select reportB.网元名称 from reportB)
union all
select * from reportA where checksum(*) not in (select checksum(*) from reportB)
)a
group by 全部列名
having count(1)=1