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

前端 未结 4 722
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  离开以前
    2021-01-04 20:22

    What's the most efficient way of doing this?

    I believe a JOIN will be more efficient than EXISTS

    SELECT t1.* FROM myTable t1
    JOIN (
        SELECT cardnumber, membertype
        FROM myTable
        GROUP BY cardnumber, membertype
        HAVING COUNT(*) > 1
    ) t2 ON t1.cardnumber = t2.cardnumber AND t1.membertype = t2.membertype
    

    Query plan: http://www.sqlfiddle.com/#!2/0abe3/1

提交回复
热议问题