Use `is distinct from` to match `null` records
Let's say you want to find all purchases that don't match a specific coupon. You can use !=
to filter them:
select * from purchases where coupon != 'JULY4';
The problem with that is that it doesn't match records that have null
values. One way to solve that is by doing a or
:
select * from purchases where coupon != 'JULY4' or coupon is null;
Better than that is to use is distinct from
:
select * from purchases where coupon is distinct from 'JULY4';
Tweet