如何找到重复的字段组合 [英] How to find duplicate field combo
本文介绍了如何找到重复的字段组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含 id、a 和 b 列的表.
I have a table with columns id, a, and b.
a+b 应该是唯一的,但这是一个没有正确约束的旧数据库.如何为 a+b 不唯一的记录获取一组 id?
a+b should be unique, but this is a legacy database that is not constrained correctly. How can I get a set of ids for records in which a+b is not unique?
如果我有
ID A B
1 2 3
2 2 3
3 1 3
4 1 4
然后我想从查询中取回记录 1 和 2.
Then I want to get records 1 and 2 back from the query.
推荐答案
select
id, a, b
from your_table t
join (select a, b from your_table group by a, b having count(1) > 1) dup on dup.a = t.a and dup.b = t.b
这篇关于如何找到重复的字段组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文