Creating Microsoft Access Queries
Creating Microsoft Access Queries
You can use a query to view a subset of your data or to answer questions about your data. For
example, if you want to view a list of student names and email addresses, but you do not want
to see addresses and other data, you can create a query that displays the students first name,
last name, and email address only. Alternatively, if you want to know which students live in
DE, you can restrict your list to those students. This lesson teaches you how to create a query.
You can use an Access query to retrieve multiple columns of data. On the Field line in Query
Design view, choose the field name of each field you want to retrieve in the order you want to
retrieve them.
To retrieve multiple columns:
Sort a Query
When creating a query, you can sort the rows you retrieve in ascending or descending order
by choosing the option you want on the Sort row in Query Design view.
To perform a sort:
<>
>
>=
Meaning
Equal to
Field Type
Character
Number
Date
Not equal to
Character
Number
Date
Greater than
Character
Number
Date
Greater than orCharacter
Entry Format
=
=
= #2/16/88#
<>
<>
<> #2/16/88#
>
>
> #2/16/88#
>
=
"DE"
5
"DE"
5
"DE"
5
"DE"
equal to
<
<=
In
Number
Date
Less than
Character
Number
Date
Less than orCharacter
equal to
Number
Date
Equal to anyCharacter
item in a list
Number
Date
Not In
Between
Between
twoCharacter
values,
Number
greater than orDate
equal to one and
less than or
equal to the
other
Not
betweenCharacter
two values
Number
Date
Not Between
Is Null
Is Not Null
Like
Not Like
>
=
5
> = #2/16/88#
<
"DE"
<
5
< #2/16/88#
<=
"DE"
<=
5
<= #2/16/88#
In
("DE",
"NJ")
In
(5,
9,
17)
In (#2/16/88#, #2/3/90#,
#12/15/88#)
Not
In
("DE",
"NJ")
Not
In
(5,
9,
17)
Not In (#2/16/88#, #2/3/90#,
#12/15/88#)
Between "C" And "F"
Between
5
And
10
Between
#1/1/88#
And
#12/31/88#
Like
Like
Not Applicable
"S*"
"1*"
single character.
When using the Like and Not Like criteria, where you place the asterisk(*) or question mark
(?) determines the type of search Access performs. Like "Jo*" finds all records in the field
that begin with Jo. It would find Jones, Johnson, and Jordan. Like "*son" finds all records in
the field that end with son. It would find Stevenson, Jackson, and Peterson. Like "*456*"
finds all records that contain 456 anywhere in the field. It would find 456123789, 123456789,
and 123789456. The sequence Like "?en" finds all three character field entries where the
second and third characters are en. It would find Ben, Len, and Jen. The sequence Like
"Jo?" finds all three character field entries where the first and second characters are Jo. It
would return Joe, Joy, and Jon. The sequence Like "T?m" finds all three character field
entries where the first and third characters are T and m. It would return Tim, Tom, and Tam.
To retrieve specific records:
If you want to view data from two or more tables or queries, you can create a query that pulls
the data from multiple tables or queries. The tables and queries from which you pull your data
should have a relationship.
To create a query that uses two or more tables:
1. Open the tables and/or queries you want to use in Query Design view.
2. Choose the field names you want to retrieve in the order you want to retrieve them.
3. Choose the field names you want to sort by in the order you want to sort. Under the
fields you want to sort by, choose Ascending or Descending.
4. Enter your selection criteria, if necessary (Not applicable in this example).
5. Deselect the Show button for columns you do not want to display (Not applicable in
this example).
6. Click the Run button. Access retrieves the columns you chose and displays the rows
in the order you specified.
Save a Query
After you create a query, you can save it. You can rerun a saved query at any time. If you
change the data on which the saved query is based, you will see the changes when you rerun
the query.
To save a query:
1. Click the Save button on the Quick Access toolbar. Access saves the query unless you
are saving for the first time. If you are saving for the first time, the Save As dialog box
appears.
2. Type the name you want to give your query.
3. Click OK. Access saves the query. You can now access the query by using the
Navigation pane.
Tip: You can also save by right-clicking a querys tab and then selecting Save from
the menu that appears. Access saves the query unless you are saving for the first time. If you
are saving for the first time, the Save As dialog box appears. Type the name you want to give
the query and then click OK. Access saves the query. You can now access the query by using
the Navigation pane.
Tip: After you have saved a query, you can run it by opening the Navigation pane
and then clicking the name of the query.
Modify a Query
Once created, a query can be modified. Simply open the query in Query Design view and
make the changes. You can add columns, change the sort order, change the criteria, and make
other changes.
In Query Design view, the Query Setup group offers several options that can assist you. Use
the Insert Rows button to insert a row in the criteria area. Click anywhere in the row before
which you want to insert a new row and then click the Insert Rows button.
1. Open the table or query on which you want to base your new table on in Query
Design view.
2. Enter the criteria on which you want to base your new table.
3. Click the Make Table button. The Make Table dialog box appears.
4. Type the name you want to give your new table.
5. Click OK.
6. Click Run. You see the following prompt.
7. Click Yes.
8. Close the query. (Right-click the querys tab and then click Close.)
9. Double-click the new tables name in the Navigation pane to view the new table.
Note: If you want to make your user prompt more flexible, use one of the
following formats.
> [Prompt]