Chapter 4. Better WHERE Clauses: Filtering Rows
Here’s your opportunity to dig in. You’ve already tried out WHERE for simple table row filters, but now you can perform an in-depth exploration of WHERE to see what it can really do.
In this chapter, you’ll use AND to find rows that meet two or more requirements. You’ll switch to OR if you want rows that satisfy any of several conditions. And you will even unearth new operator artifacts to aid in your quest for missing items, ranges of values, or text patterns.
So what are you waiting for? Turn the page and let the excavation begin. WHERE is your new best friend.
Misplaced identification
Uh oh, Abby doesn’t look happy. Let’s check back in with her to see what’s going on.
We can use a SELECT query with the filter:
to find Abby some locations within the USA so she won’t need her passport to travel. Here’s the first few results:
Multiple row requirements
We were able to find locations within the United States, but Abby and her friend Katie wouldn’t need to fly to all of the places we found.
What if we try a SELECT query but use a filter to require plane travel?
The first few rows of those results give us:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access