今天sql群里有人问:如何去掉重复的记录而保留其中的一条
其实这是一个老的话题
有人说:select distinct *from tableName
其实这只是得到无重复的数据集,并没有删除表中的记录
我想到到的是
select distinct * into #TempTable from tableName
drop table tableName
select * into tableName from #TempTable
drop table #TempTable
其实是利用临时表选取不重复的记录集导入到临时表删除表,然后
再把临时表中的数据再导进来
Sql去掉重复行
最新推荐文章于 2023-08-24 09:49:05 发布