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.
这篇关于选择语句以查找某些字段的重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:选择语句以查找某些字段的重复项


- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01