I'm using the standard world schema that comes with MySQL Workbench. I initially tried this query to give me all of the cities in the United States; however, I kept getting one row of null entries at the bottom.
select *
from city
where CountryCode = 'USA';
I looked up a solution and found MySQL SELECT only not null values. So, next I tried this:
select *
from city
where Name is not null and CountryCode = 'USA';
which gave me the exact same thing as the first query. So, I decided to take a different approach. Instead of getting multiple columns, I wanted to see if I could just get the Name
column:
select Name
from city
where CountryCode = 'USA';
Much to my surprise, this worked fine, and without me having to check for null
.
So my question is two-fold:
- Why did my second approach give me the row of
nulls
at the bottom (also how to fix it), and - Why did the last approach not give me a
null
at the bottom?
EDIT: Additional Info
Also, not sure if this is important, but despite the fact that the first two queries returned a row with nulls
at the bottom, for all three queries, I got the same number of returned rows.
Here's the output from the first two queries:
Here's the output from the last one: