SQL equality & NULL operators


What's inside this article ⌄
  • SQL null comparison operators
  • SQL IS NULL vs equals NULL
  • SQL inequality operators difference
  • Postgres comparison operators

There are a bunch of comparisons in SQL:

=, <>, !=, IS, and IS NOT

it’s time to refresh the knowledge.

If you want to check a column for NULL, you should use IS and IS NOT:

select * from users where address is NULL;
select * from users where address is not NULL;

The thing is that all other comparison operators will not work for this type of thing. IS and IS NOT are specifically tailored for NULL checks.

With ordinary comparisons, you should use = (equality) and <> (inequality):

select * from users where age = 25; -- equals
select * from users where age <> 30; -- not equals

Note that the != inequality operator is not being supported by all databases. You can use it only if your database supports it.