IS NULL and
IS NOT NULL are used in
either display rows for which there is no value in a specified column or to
show only those rows which have a value in the specified column.
In the outcome table of our dataset there is the column
contains the different outcomes for the animals at the center. Some of the
possible outcomes are further defined by subtypes captured in the
outcome_subtype field. If we wanted to return only data that has both an
outcome type and an outcome subtype we could write the query thus:
SELECT monthyear, animal_type, outcome_type, outcome_subtype FROM austin_animal_center_outcomes WHERE outcome_subtype IS NOT NULL
and the first several rows returned would look like this:
Exercises (Continued from previous section)
The exercises below can be run from the “Try query” link below, but they cannot be saved. If you would like to save your queries, see this article for instructions. You can also do the exercises from a complete stand-alone tutorial located here.
Using the patient, description, and reasondescription columns from the medications table, write a query that returns the records where reasondescription is not null.
SELECT the columns
IS NOT NULL.
An introduction to the
NOT LIKE keywords.