查找多列重复项 mysql [英] finding multi column duplicates mysql

查看:54
本文介绍了查找多列重复项 mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到多列的重复记录?表有主键(自增)

How can i find the duplicate records for multi column ? Table has primary key (Auto increment)

EG

 ID  a_id  b_id
 ---- ---- ------
   1    34   23
   2    34   23
   3    35   25

例如我想查找具有相同 a_id 和 b_id 的记录...

for example i want to find records with same a_id and b_id...

谢谢

推荐答案

select t.ID, t.a_id, t.b_id
from (
  select a_id, b_id
  from tbl
  group by a_id, b_id
  having count(*) > 1) x, tbl t
where x.a_id = t.a_id and x.b_id = t.b_id
order by t.a_id, t.b_id

此查询将显示元组 (a_id, b_id) 上的所有重复项

This query will show you all the duplicates on the tuple (a_id, b_id)

这篇关于查找多列重复项 mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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