Use the OR criteria to query on alternate or multiple conditions
To see information when either two or more alternate criteria are satisfied, use the or criteria rows in the Access query design grid.
If you'd like a refresher, see applying criteria to a query.
For example, if a business has customers in several different countries and they are running a promotion only for customers in France, UK and USA. To get a list of customers from just these countries, here's how you can use the OR row:
-
Open the table that you want to use as your query source and on the Create tab click Query Design.
-
In the Query Designer, select the table, and double-click the fields that you want displayed in the query results.
-
Add your first criterion in the Criteria row.
Note: Use the appropriate column, we've used the Country/Region in this example but if you want to locate specific last names, you'd add the criteria in the Last Name field.
-
Add the alternate criteria in the or row and if you have more than one use the empty rows below, and click Run.
-
Press CTRL+S to save the query.
Another example of the OR criteria: Find employees who work in the Chicago branch office OR employees whose birthday falls on a specific date:
1. The City criterion is specified in the Criteria row.
2. The BirthDate criterion is specified in the or row.
Criteria specified in the Criteria and or rows are combined using the OR operator, as shown below:
City = "Chicago" OR BirthDate < DateAdd (" yyyy ", -40, Date())
It is possible to specify more alternatives, by using the empty rows below the or row.
Tip: If the criteria are temporary or changes often, a better option is to filter for the query result.
Using the OR criteria across different fields
The following picture shows how you can use the OR criteria row for alternate criteria in different fields like finding companies whose customers live either France or London.
Tip: When you use a criterion that is also a keyword use double quotes around the criteria, for example, OR and IN are logical operators and also the abbreviations for Oregon and Indianaso, ""OR"".
If the criteria fields don't change, but the values that you want to use do change frequently, you can create a parameter query.
Check out these examples of query criteria.
No comments:
Post a Comment