日期:2014-05-18  浏览次数:20428 次

sql查询重复记录的一条 效果加效率
1.select distinct a,b,c from d where b=1
这样好象不行啊 取a的值 distinct后面是不是只能加一个字段 

2.select a,b,c from d group by a,b,c
 这样可以不?group by后面一定一定要列出select的字段 除了max啊什么的 是吗?

3.select a,b,c from d where a in(select distinct a from d)
这样行不行 跟2比谁的效率高

------解决方案--------------------
3.select a,b,c from d where a in(select distinct a from d) 
这样行不行 跟2比谁的效率高
这条查什么呢?这个不是查重复的吧
select a,b,c from d where a in (select a from d group by a having count(*)>1)
------解决方案--------------------
--只查a重复
select * from tb where a in (select a from tb group by a having count(*) > 1)
--查a,b同时重复
select * from tb where cast(a as varchar) + ',' + cast(b as varchar) in (select cast(a as varchar) + ',' + cast(b as varchar) from tb group by cast(a as varchar) + ',' + cast(b as varchar) having count(*) > 1)