• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Unleashing the Power of Queri... > Understanding “Ands” and “Ors” in th...

Understanding “Ands” and “Ors” in the Query Grid

If you want to construct a query with multiple criteria, you need to understand the difference between the logical operators And and Or. Although these operators can combine more than two conditions, for the sake of simplicity, let’s use just two. Start with the premise that an And operator selects records only if both conditions in a two-condition query are met. In contrast, an Or operator selects records only if one or the other condition in a two condition query are met. In other words, at least one condition in an Or query must be met.

This is where it gets a little tricky. Suppose you want to see both the Colorado and the Mississippi losses in the Losses table. You would think that you could just type CO And MS in the AccidentState column and retrieve those records. This criteria retrieves nothing. How can this be? You must think of it on a record-by-record basis. SQL examines each record to see if both conditions are met. Of course, it finds nothing because there is not a single record that has both Colorado and Mississippi values in the AccidentState field. This is why you would normally use two or more fields to create an And condition in the query grid.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint