select distinct * from tableName
得到无重复记录的结果集。
如果该表需要删除重复的记录(重复记录保留1条),可以按以下方法删除
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
另一种方法是一个字段重复,ID不重复
delete 表 where id not in(
SELECT MAX(id) AS id FROM 表 GROUP BY rows) --- 删除重复行
select * from 表 where id in(
SELECT MAX(id) AS id FROM 表 GROUP BY rows) --重复行只查询一条
得到无重复记录的结果集。
如果该表需要删除重复的记录(重复记录保留1条),可以按以下方法删除
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
另一种方法是一个字段重复,ID不重复
delete 表 where id not in(
SELECT MAX(id) AS id FROM 表 GROUP BY rows) --- 删除重复行
select * from 表 where id in(
SELECT MAX(id) AS id FROM 表 GROUP BY rows) --重复行只查询一条