select * from tablename a where not exists (select 1 from tablename where A字段=a.A字段) or B字段='小明'
楼主没说清楚,如果有重复,而且没有B字段='小明'的记录怎么显示我的语句是都不显示1楼错了,改下select * from tablename a where not exists (select 1 from tablename where A字段=a.A字段 and B字段<>a.B字段) or B字段='小明'
where not exists (select 1 from tablename where A字段=a.A字段)
or B字段='小明'
where not exists (select 1 from tablename where A字段=a.A字段 and B字段<>a.B字段)
or B字段='小明'
比如:
A B
12345678 小花
12345678 小林
12345678 小噢
要显示哪个?
就是只要后面的条件满足,选出来的结果就为1
这里你也可以换为其他的2,3,*啊什么的~