The Most Underrated SQL Gotcha
You have no idea how many times this one has tripped me up.
Start with something simple:
where column = 'A'
No surprises there, you get all the rows where column is 'A'.
Now flip it around:
where column != 'A'
You’d think that means “everything except A.”
But nope, you just lost every row where column is null.
That’s because in SQL, comparisons with null aren’t true or false, they’re unknown. And where filters out anything that isn’t true.
So instead of “everything but A,” what you really get is “everything but A and all the nulls.”
It’s a tiny detail, but it can seriously skew results if those nulls actually mean something, like users who haven’t taken an action yet or missing event data.
When it matters, make it explicit:
where column != 'A' or column is null
One little condition, and your query suddenly behaves the way you thought it did all along.