选择语句以查找某些字段的重复项

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

问题描述

您能帮我用 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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)