如何从SQL表中删除所有重复的记录? [英] How to delete all duplicate records from SQL Table?

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

问题描述

您好,我的表名 FriendsData 包含重复的记录,如下所示

Hello I have table name FriendsData that contains duplicate records as shown below

fID UserID  FriendsID       IsSpecial      CreatedBy
-----------------------------------------------------------------
1   10         11            FALSE            1
2   11          5            FALSE            1
3   10         11            FALSE            1
4    5         25            FALSE            1 
5   10         11            FALSE            1
6   12         11            FALSE            1
7   11          5            FALSE            1
8   10         11            FALSE            1
9   12         11            FALSE            1

我想使用MS SQL删除重复的组合行吗?
从MS SQL FriendsData表中删除最新的重复记录. 在这里,我附加了突出显示重复列组合的图像.

I want to remove duplicate combinations rows using MS SQL?
Remove latest duplicate records from MS SQL FriendsData table. here I attached image which highlights duplicate column combinations.

如何从SQL表中删除所有重复的组合?

How I can removed all duplicate combinations from SQL table?

推荐答案

尝试一下

DELETE
FROM FriendsData 
WHERE fID NOT IN
(
SELECT MIN(fID)
FROM FriendsData 
GROUP BY UserID, FriendsID)

请参见此处

或者此处是做您想要的更多方法

Or here is more ways to do what you want

希望这会有所帮助

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

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