如何从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

希望这会有所帮助