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
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
Maybe this code will help you
select Friend_E_Mail
From Friends
WHERE 'carl@pam.com' NOT IN(Friend_E_Mail, My_E_Mail)