Can someone explain to me how SQL deals with null data?

I’m here working on the CIA Facebook SQL project, and one of the first prompts is to look at minimum/maximum populations:

Ordering by population, I noticed there were a lot of null values that come before an integer value of 0. However, when I query specifically for the minimum value for population, it gives me 0. I’m fine up until this point. My confusion starts here:

When I subquery the data to give me rows that do not contain the max or min population, it removes null values as well. So essentially I am looking for clarification as to what queries will treat null values as values to consider, and what queries will ignore them. And also, why?

1 Like

Hi @spatterss135

You didn’t mention if you have Googled for null value treatment. And I am not sure if I understood your question right.

The foremost challenge with Null value is its interpretability. For instance, for a numeric column, we might be inclined to treat a null value as 0 but what if it’s a hidden value?

The below articles have a nice explanation about Null values and how to work with them. They might be able to give you a hint to narrow down your search for the questions:

1 Like