如:表A,
a b c d
ems1 1 2 2
ems1 1 3 3
ems1 2 4 6
ems1 3 A H
ems1 2 4 3
ems1 4 B 2
查询表A,要求列出所有的列.执行2次查询,第1次是b列的数据不出现重复的;第2次是b列,d列的数据都不出现重复的.
select * from a a1
where not exists (
select b from a a2 --加表a别名a2
where a2.b=a1.b
group by b
having count(*)>1
)
select * from a a1
where not exists (
select b,d from a a2 --加表a别名a2
where a2.b=a1.b