I have an issue, where SQL queries do not work correctly for blank values.
A very brief summary:
- I have TABLE A with 200k rows (no duplicates). In this table there is field called MailingCountry. Sometimes this field is blank.
- I have TABLE B with 50k rows (no duplicates), which is a subset of TABLE A built using a query
- I have TABLE C with 10k rows (no duplicates), which is a subset of TABLE A buolt using a filter where MailingCountry is not equal 'NZ' or 'New Zealand'
I should get the same results if I do either of the following:
- Run the below query:
SELECT *
FROM [TABLE A] a
LEFT JOIN [TABLE B] b
ON a.ContactKey = b.SubscriberKey
WHERE b.SubscriberKey IS NULL
AND a.MailingCountry <> 'NZ'
AND a.MailingCountry <> 'New Zealand'
- Run the below query:
SELECT *
FROM [TABLE A] a
LEFT JOIN [TABLE B] b
ON a.ContactKey = b.SubscriberKey
LEFT JOIN [TABLE C] c
ON a.ContactKey = c.ContactKey
WHERE b.SubscriberKey IS NULL
AND c.ContactKey IS NULL
However, I get completely different results. Doing the maths manually it is clear that query 1 is also removing rows where MailingCountry = '' (ie has a blank value)
Is this a known issue? Or a bug? Or have I stuffed something up?
Thanks
OR a.MailingCountry IS NULL
to your query as Null values do not show as true or false but undefined, so will be removed in filters like that.