7 Filtering with wildcards and null values

 

The preceding chapters are filled with different ways to filter the data returned by your queries using numerous comparison operators. We’ve worked with many methods for filtering on one or more values of equality or inequality using known values or ranges of values. Let’s take one more chapter to examine some interesting ways to search for less specific data.

We’ll look at how to filter data when we don’t know the exact values to be searched. Instead of searching for specific values, we’ll search for patterns of values. This approach can be incredibly useful when we want to look for a list of products that have specific text like tomato or cable in the name, or when we want a list of all customers whose last name starts with the letter A.

We’ll also look at the trickiest value to search on: null. Null values are commonly misunderstood, and as such, they often lead to incorrect query results. We’ll examine what a null value is (and isn’t) and how to query for null values.

7.1 Filtering with wildcards

In chapter 6, you learned how to search ranges of numeric or date values. Even though you may not know all the specific values you want from a range, you know how to query the correct results using operators such as >, <, and BETWEEN.

7.1.1 Filtering with the percent sign

7.1.2 Filtering with an underscore

7.2 Filtering with null values

7.2.1 How not to search for null values

7.2.2 How to search for null values correctly

7.2.3 How to search for values that are not null

7.3 Lab

7.4 Lab answers