同表单字段
select * from test_hangzhuanlie
where BRANCH_CODE in (select BRANCH_CODE from test_hangzhuanlie group by BRANCH_CODE having count(BRANCH_CODE) > 1)
不同表单字段
select * from tb
where name in (select stunm from student group by stunm having count(stunm) > 1 )
删除重复
delete from tb
where name in (select stunm from student group by stunm having count(stunm) > 1 )
查重可统计个数
Select Name,Count(*) From tb Group By Name Having Count(*) > 1
Select Name,courses,Count(*) From tb Group By Name,courses Having Count(*) > 1
使用distinct
select distinct * from tableName
distinct下,删除重复记录
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
查询某一列不重复的记录
SELECT * FROM INDX WHERE IDX_NO IN (SELECT MIN(IDX_NO) FROM INDX GROUP BY Name)
多个字段
SELECT T.* FROM tb T,(
SELECT NAME,COURSES
FROM tb
GROUP BY NAME,COURSES
HAVING COUNT(1)>1
) AS S
WHERE T.NAME=S.NAME AND T.COURSES=S.COURSES