如何删除表中的重复行 [英] How can I delete duplicate rows in a table

查看:130
本文介绍了如何删除表中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,说3列。没有主键,因此可以有重复的行。我需要只保留一个,删除其他人。任何想法如何做到这一点是Sql Server?

I have a table with say 3 columns. There's no primary key so there can be duplicate rows. I need to just keep one and delete the others. Any idea how to do this is Sql Server?

推荐答案

我将SELECT DISTINCT的行,然后删除源表并从temp中复制数据。
EDIT:现在带有代码段!

I'd SELECT DISTINCT the rows and throw them into a temporary table, then drop the source table and copy back the data from the temp. now with code snippet!

INSERT INTO TABLE_2 
SELECT DISTINCT * FROM TABLE_1
GO
DELETE FROM TABLE_1
GO
INSERT INTO TABLE_1
SELECT * FROM TABLE_2
GO

这篇关于如何删除表中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆