Find rows with parameter in one of two columns?

后端 未结 2 1413
灰色年华
灰色年华 2021-01-24 09:14

I have this table and need help

Friends:

My_E_Mail (VARCHAR) Friends_E_Mail(VARCHAR) 
alester@pam.com carl@pam.com
alester@pam.com greg@pam.com
alester@pam.co         


        
相关标签:
2条回答
  • 2021-01-24 09:49

    Try

    DELCARE @email VARCHAR(50) = ?
    WITH FRIENDS_CTE (My_E_Mail, Friend_E_Mail)
    AS
    (
      SELECT My_E_Mail, Friends_E_Mail
      FROM FRIENDS
      WHERE My_E_Mail = @email
      UNION 
      SELECT Friends_E_Mail, My_E_Mail
      FROM FRIENDS
      WHERE Friends_E_Mail = @email
    )
    SELECT Friend_E_Mail
    FROM FRIENDS_CTE
    WHERE My_E_Mail = @email
    
    0 讨论(0)
  • 2021-01-24 09:55

    Maybe this code will help you

    select Friend_E_Mail
    From Friends 
    WHERE 'carl@pam.com' NOT IN(Friend_E_Mail, My_E_Mail)
    
    0 讨论(0)
提交回复
热议问题