Skip to Content
Navigation:

A stick figure smiling

Here's a preview from my zine, Become a SELECT Star!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

browse more comics! get the zine!
read the transcript!

NULL isn’t equal (or not equal!) to anything in SQL (x = NULL and x != NULL are never true for any x). This results in 2 behaviours that are surprising at first:

Surprise! x= NULL doesn’t work

fish
name: NULL owner: bob
name: nemo owner: ahmed

SELECT * FROM fish  
WHERE name = NULL 

no results!
You need to use x IS NULL instead.

works
name IS NULL
name IS NOT NULL

doesn’t work
name = NULL
name != NULL

surprise! name != ‘betty’ doesn’t match NULLs

fish
name: NULL owner: bob
name: nemo owner: ahmed

SELECT FROM fish
WHERE name != 'betty'

name: NULL owner: bob

To match NULLS as well, I’ll often write something like WHERE name = 'betty' OR name IS NULL instead.

more surprising truths

More operations with NULL which might be surprising:

2 + NULL => NULL
NULL * 10 => NULL
CONCAT(‘hi’, NULL) => NULL
NULL = NULL => NULL (NULL isn’t even equal to itself!)
2 = NULL => NULL
2 != NULL => NULL

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2021 | All rights reserved (see the FAQ for notes about licensing)