如何从 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
希望对你有帮助
相关文章