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

前端 未结 4 724
被撕碎了的回忆
被撕碎了的回忆 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:08

    You can use exists for this:

    select * 
    from yourtable y
    where exists (
      select 1
      from yourtable y2 
      where y.name <> y2.name
        and y.cardnumber = y2.cardnumber
        and y.membertype = y2.membertype)
    
    • SQL Fiddle Demo

提交回复
热议问题