Examples of Query Criteria
Examples of Query Criteria
Access for Microsoft 365 Access 2021 Access 2019 Access 2016
To add criteria to an Access query, open the query in Design view and
identify the fields (columns) you want to specify criteria for. If the field is not
in the design grid, double-click the field to add it to the design grid and then
enter the criterion in the Criteria row for that field. If you’re not sure how to
make this happen, see Introduction to queries.
Here are some examples of commonly used criteria you can use as a starting
point to create your criteria. The examples are grouped by data types.
In this topic
Introduction to query criteria
Criteria for Text, Memo, and Hyperlink fields
Criteria for Number, Currency, and AutoNumber fields
Criteria for Date/Time fields
Criteria for Yes/No fields
Criteria for other fields
The following tables shows some sample criteria and explains how they work.
Criteria Description
>25 and <50 This criterion applies to a Number field, such as
Price or UnitsInStock. It includes only those
records where the Price or UnitsInStock field
contains a value greater than 25 and less than
50.
DateDiff This criterion applies to a Date/Time field, such
("yyyy", as BirthDate. Only records where the number of
[BirthDate], years between a person's birthdate and
Date()) > 30 today's date is greater than 30 are included in
the query result.
Is Null This criterion can be applied to any type of field
Criteria Description
to show records where the field value is null.
As you can see, criteria can look very different from each other, depending
on the data type of the field to which they apply and your specific
requirements. Some criteria are simple, and use basic operators and
constants. Others are complex, and use functions, special operators, and
include field references.
This topic lists several commonly used criteria by data type. If the examples
given in this topic do not address your specific needs, you might need to
write your own criteria. To do that, you must first familiarize yourself with the
full list of functions, operators, special characters, and the syntax for
expressions referring to fields and literals.
Here, you will see where and how you add the criteria. To add a criteria to a
query, you must open the query in Design view. You then identify the fields
for which you want to specify criteria. If the field is not already in the design
grid, you add it by either dragging it from the query design window to the
field grid, or by double-clicking the field (Double-clicking the field
automatically adds it to the next empty column in the field grid.). Finally, you
type the criteria in the Criteria row
Criteria that you specify for different fields in the Criteria row are combined
by using the AND operator. In other words, the criteria specified in the City
and BirthDate fields are interpreted like this:
City = "Chicago" AND BirthDate < DateAdd (" yyyy ", -40, Date())
1. The City and BirthDate fields include criteria.
2. Only records where the value of the City field is Chicago will satisfy this
criterion.
3. Only records of those who are at least 40 years old will satisfy this criterion.
4. Only records that meet both criteria will be included in the result.
What if you want only one of these conditions to be met? In other words, if
you have alternate criteria, how do you enter them?
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())
If you need to specify more alternatives, use the rows below the or row.
Before you continue with the examples, note the following:
If the criteria is temporary or changes often, you can filter the query result
instead of frequently modifying the query criteria. A filter is a temporary
criterion that changes the query result without altering the design of the
query. For more information about filters, see the article Apply a filter to
view select records in an Access database.
If the criteria fields don't change, but the values you are interested in do
change frequently, you can create a parameter query. A parameter query
prompts the user for field values, and then uses those values to create the
query criteria. For more information about parameter queries, see the
article Use parameters in queries and reports.
A criterion that you specify for a Hyperlink field is, by default, applied to the
display text portion of the field value. To specify criteria for the destination
Uniform Resource Locator (URL) portion of the value, use
the HyperlinkPart expression. The syntax for this expression is as
follows: HyperlinkPart([Table1].[Field1],1) =
"http://www.microsoft.com/", where Table1 is the name of the table
containing the hyperlink field, Field1 is the hyperlink field, and
http://www.microsoft.com is the URL you want to match.
instead of
the < operator.
Contain > #2/2/2006# Returns records
values of transactions
that fall that took place
after a after Feb 2, 2006.
certain
To view
date,
transactions that
such as
took place on or
2/2/2006
after this date,
use
the >= operator
To Use this criterion Query result
include
records
that ...
instead of
the > operator.
Contain >#2/2/2006# and <#2/4/2006# Returns records
values where the
that fall transactions took
within a place between
date Feb 2, 2006 and
range Feb 4, 2006.
Lookup fields that are based on a list of specified values are of the Text data
type, and valid criteria are the same as for other text fields.
The criteria you can use in a Lookup field based on values from an existing
datasource depend on the data type of the foreign key, rather than the data
type of the data being looked up. For example, you may have a Lookup field
that displays Employee Name, but uses a foreign key that is of the Number
data type. Because the field stores a number instead of text, you use criteria
that work for numbers; that is, >2.
If you do not know the data type of the foreign key, you can inspect the
source table in Design view to determine the data types of the field. To do
this:
3. The data type for each field is listed in the Data Type column of the table
design grid.