SQL - select rows that have the same value in two columns

前端 未结 4 750
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 19:50

The solution to the topic is evading me.

I have a table looking like (beyond other fields that have nothing to do with my question):

NAME,CARDNUMBER,MEMBERTY

4条回答
  •  Happy的楠姐
    2021-01-04 20:26

    If you just need to know the valuepairs of the 3 fields that are not unique then you could simply do:

    SELECT   concat(NAME, "|", CARDNUMBER, "|", MEMBERTYPE) AS myIdentifier, 
             COUNT(*) AS count
    FROM     myTable 
    GROUP BY myIdentifier
    HAVING   count > 1
    

    This will give you all the different pairs of NAME, CARDNUMBER and MEMBERTYPE that are used more than once with a count (how many times they are duplicated). This doesnt give you back the entries, you would have to do that in a second step.

提交回复
热议问题