How to Compare Two Values When One is NULL in Snowflake

Say you're comparing two Snowflake columns and you want to know how many rows are different. No problem, you think:

select count(1)
from sessions
where start_date != end_date;

Wait a minute. If some of the start or end dates are null, they won't be counted! 😬 That's definitely not what you wanted. That's why you need to use the INTERSECT operator:

select count(1)
from sessions
where not exists(select start_date from sessions intersect select end_date from sessions);

Now, your count will be “null aware” and you'll get the result you want.

database icon
Shared queries and folders ✅ Version history ✅ One-click connection to Snowflake ✅
Get more done, together, with PopSQL and Snowflake