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!

Image of a comic. To read the full HTML alt text, click "read the transcript".

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

NULL is a special state in SQL. It’s very commonly used as a placeholder for missing data (“we don’t know her address!”)

What NULL means exactly depends on your data. For example, it’s really important to know if allergies IS NULL means:

  • “no allergies” or
  • “we don’t know if she has allergies or not”

NULL “should” mean “unknown” but it doesn’t always.

smiling stick figure with curly hair: it would be easier if NULL always meant the same thing but it really depends on your data!

where NULLs come from

  • There were already NULL values in the table
  • The window function LAG() can return NULL
  • You did a LEFT JOIN and some of the rows on the left didn’t have a match for

tiny pensive stick figure with curly hair: ooh, not very cat has an owner so sometimes the owner name is NULL

ways to handle NULL s *

  • Leave them in!

smiling stick figure with curly hair: I’d rather see a NULL and know there’s missing data than get misleading results

  • Filter them out!
    ... WHERE first_name IS NOT NULL ...

  • Use COALESCE or CASE to add a default value

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 2024 | All rights reserved (see the FAQ for notes about licensing)