[SalesForce] SQL Query contacts not in another data extension

Attempting to query based on a data extension called [Users], but I want to extract ALL the contacts that are also in the [Unsubscribe] data extension.

I thought it would be a simple 'NOT IN' function, but do I need to INNER JOIN, as well?

SELECT * FROM ENT.[Users] WHERE Email Address NOT IN ENT.[Unsubscribe]

Best Answer

First if that's the "Email Address" field, you would have to put it in brackets [Email Address]. I suspect there is no space between them (EmailAddress).

I would use this as I have found it to work well for me when excluding fields present in another DE.

SELECT 

t.Email, 
t.Platform_User_Id, 
t.First_Name, 
t.Last_Name, 
t.Created_At, 
t.Last_Login_At, 
t.platform 

FROM ENT.[Users] t

LEFT JOIN ENT.[Unsubscribe] u

ON t.EmailAddress = u.EmailAddress

WHERE u.EmailAddress IS NULL
Related Topic