Select multiple rows with the same value(s)

前端 未结 5 1097
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 10:17

I have a table, sort of like this:

ID  |  Chromosome | Locus | Symbol | Dominance |
===============================================
1   |      10     |   2           


        
5条回答
  •  时光取名叫无心
    2020-12-13 10:19

    One way of doing this is via an exists clause:

    select * from genes g
    where exists
    (select null from genes g1
     where g.locus = g1.locus and g.chromosome = g1.chromosome and g.id <> g1.id)
    

    Alternatively, in MySQL you can get a summary of all matching ids with a single table access, using group_concat:

    select group_concat(id) matching_ids, chromosome, locus 
    from genes
    group by chromosome, locus
    having count(*) > 1
    

提交回复
热议问题