在日常日常应用中,经常需要查询出数据表中重复的数据,以便对其进行删除等操作。以下是T-SQL查询数据表中重复数据的几种方法:
例如 表test_a
id name
1 aa
2 bb
3 cc
4 dd
5 ee
8 aa
9 ee
查询结果:
1 aa 2 bb 3 cc 4 dd 5 ee 方法1: select A.* from test_a as A where id not in(select min(id) as oldid from test_a group by name) 方法2: select * from test_a where not id in(select max(id) from test_a group by name having count(name)>1)