Documente Academic
Documente Profesional
Documente Cultură
Access 2013
Queries
11
Objectives
Maintain a database
Understand action queries
Create an Update query
Create an Append query
Use a make table query
Create a delete query
Create find unmatched queries
Understand find duplicate queries
2
Queries
What is a query?
A query is actually the name for any
database manipulation operation.
The most commonly used type is a select
query, which is a way of selecting what
fields in what records are to be displayed.
Creating a query
You can create only very simple queries
by using the Query Wizard.
We’ll create all Queries using the Design
View for queries.
Once designed, the results of a query can
be displayed in Datasheet View.
Select queries
A select query is the most common type of
query.
It retrieves data from one or more tables and
displays the results in a datasheet where
you can update the records (with some
restrictions).
You can also use a select query to group
records and calculate sums, counts,
averages, and other types of totals.
ACTION QUERIES
Action Queries
Change underlying table data
Select queried do not
Can be used to create new tables
Cannot be undone
Play a large role in maintaining a database
8
Types of queries you can create
in Microsoft Access
Select queries
Crosstab queries (actually a special
kind of select query)
Action queries
Make-table queries
Delete queries
Update queries
Append queries
In addition, any of these types can be
designed to prompt the user for
information, in which case it is called a
parameter query.
i. Update Queries
Changes value(s) in one/more records
Use the Update query button
Database Tools tab, Query Type group
Update button
11
Creating an Update query
Identify record source
Show desired tables
in design grid Update
value
Switch from Select to
Update Query
Insert Field to be
updated
Enter the value to be
updated
Value entered in
Update To field
12
Testing Action Queries
Check Datasheet
View first
Criteria
15
Using Criteria with an Update
Query Before update query with criteria
Criteria
Fields to append
added to design grid
February Agents
before append
September Agents
before and after
append
20
iii. Make Table Query
21
Creating a Make Table Query
Make Table
button
Test in Datasheet
view
Results of make
table query
24
iv. Delete Queries
Can delete all records from table
Criteria used to delete specific records
If no criteria, all records deleted
25
Creating a Delete Query
Add table to Delete button
design grid
26
Running a Delete Query
Test in Design
view
Table before
delete query
Table after
delete query
Find Unmatched
Query
30
Unmatched Query Wizard
Select first table source
31
Unmatched Query Wizard
Select duplicate fields
32
About Find Duplicates Query
Query
Wizard
Find
Duplicates
query result
Finds duplicate data
Aids in data entry error detection
Allows administrative use of purposely duplicated data
Easily created with the Query Wizard
33
CRITERIA
Expressions
The And
condition.
The Or
condition.
Creating And and Or conditions
in the design grid
Before After
Aggregates: Where
Oh, Microsoft!?
PARAMETER
Parameter queries
A parameter query prompts for criteria
each time it's run.
A parameter query displays one or more
predefined dialog boxes that prompt you
for the parameter value (criteria).
You can also create a custom dialog box
that prompts for the query's parameters.
For example, suppose we often want to see
certain data for all customers living in a
particular city, where that city may be
Miami, or Coral Gables, or any one of many
other cities.
Rather than create a separate query with
the city built in, it may make more sense to
create a single parameter query that
prompts for the city before it runs.
Creating a parameter query
In the Criteria cell for each field you want
to use as a parameter, type a prompt
enclosed in square brackets([]). Microsoft
Access will display this prompt when the
query is run. The text of the prompt must
be different from the field name, although
it can include the field name.
For example, a simple modification of our
earlier query to list all customer data for
Miami customers makes it a parameter
query that prompts for the city:
For a field that displays dates, you can
display the two prompts "Type the
beginning date:" and "Type the ending
date:" to specify a range of values. In the
field's Criteria cell, type Between [Type the
beginning date:] And [Type the ending
date:].
CROSSTABLE
Crosstab queries
A crosstab query displays summarized
values (sums, counts, and averages) from
one field in a table and groups them by
one set of facts listed down the left side of
the datasheet and another set of facts
listed across the top of the datasheet.
To create a crosstab query
using a wizard
In the Database window, click the Queries
tab, and then click New.
In the New Query dialog box, click
Crosstab Query Wizard.
Click OK.
Follow the directions in the wizard dialog
boxes. In the last dialog box, you can
choose to run the query or see the query's
structure in Design view.