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

查看:40
本文介绍了如何从 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天全站免登陆