Select multiple rows with the same value(s)

前端 未结 5 1107
被撕碎了的回忆
被撕碎了的回忆 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:44

    Assuming that you want all rows for which there is another row with the exact same Chromosome and Locus:

    You can achieve this by joining the table to itself, but only returning the columns from one "side" of the join.

    The trick is to set the join condition to "the same locus and chromosome":

    select left.*
    from Genes left
    inner join Genes right
    on left.Locus = right.Locus and 
      left.Chromosome = right.Chromosome and left.ID != right.ID
    

    You can also easily extend this by adding a filter in a where-clause.

提交回复
热议问题