Learning how to filter on NULL values

You can't filter for NULL values the same way you can filter on other values. For instance, you can't use comparison operators, which were covered earlier in this chapter. These include =, >, < , and <>. You need to filter NULL values with IS NULL or IS NOT NULL.

The following query will return the results for NULL values in g_defense:

USE lahmansbaseballdb;SELECT playerid, g_all, g_batting, g_defenseFROM appearancesWHERE g_defense IS NULL;

The previous query will return the results shown in the following screenshot. All the g_defense values will be NULL:

The following query will return the results ...

Get Learn SQL Database Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.