选择语句以查找某些字段的重复项 [英] Select statement to find duplicates on certain fields

查看:29
本文介绍了选择语句以查找某些字段的重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮我用 SQL 语句查找多个字段的重复项吗?

Can you help me with SQL statements to find duplicates on multiple fields?

例如,在伪代码中:

select count(field1,field2,field3) 
from table 
where the combination of field1, field2, field3 occurs multiple times

从上面的语句中如果有多次出现我想选择除了第一条之外的每条记录.

and from the above statement if there are multiple occurrences I would like to select every record except the first one.

推荐答案

要获取有多个记录的字段列表,可以使用..

To get the list of fields for which there are multiple records, you can use..

select field1,field2,field3, count(*)
  from table_name
  group by field1,field2,field3
  having count(*) > 1

查看此链接以获取有关如何删除行的更多信息.

Check this link for more information on how to delete the rows.

http://support.microsoft.com/kb/139444

应该有一个标准来决定如何定义第一行".在您使用上面链接中的方法之前.基于此,如果需要,您将需要使用 order by 子句和子查询.如果您可以发布一些示例数据,那真的很有帮助.

There should be a criterion for deciding how you define "first rows" before you use the approach in the link above. Based on that you'll need to use an order by clause and a sub query if needed. If you can post some sample data, it would really help.

这篇关于选择语句以查找某些字段的重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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