码迷,mamicode.com
首页 > 数据库 > 详细

mysql 中如何查找相同的数据

时间:2015-10-13 01:34:09      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

思路:

在表中6,7号数据,他们的除了ID不同,其他的数据相同;首先,在表中找到一个组合主键,然后以主键group by 然后计算出大于1的记录,然后在通过组合主键找到这条记录,然后就能把记录找到了。就找了两条相同的记录,

select 
    *
from
    tb_stu as t
        join
    (select 
        count(*) as amount, t5.stuId, t5.stuName
    from
        (select 
        *
    from
        tb_stu as s) as t5
    group by stuId , t5.stuName) as t5 ON t.stuId = t5.stuId  
        and t.stuName = t5.stuName
where
    t5.amount > 1

 

mysql 中如何查找相同的数据

标签:

原文地址:http://www.cnblogs.com/rocky-AGE-24/p/4873351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!