chapter2
chapter2
1
Project-Querying a Database
• Roadmap
• Create queries in Design view
• Use criteria in queries
• Sort data in queries
• Join tables in queries
• Perform calculations in queries
2
Query
3
Creating Queries in the Design View
• Close the tables
• Click CREATE on the ribbon to
display the CREATE tab
• Click the Query Design button to
create a new query
• Click on the desired table name
and click on Add
• Click the Close button to remove the dialog box from the screen
4
Creating Queries – Cont.
• Drag the lower edge of the field list down far enough so all
fields in the table appear
5
Creating Queries – Cont.
6
Creating Queries with Criteria
7
Clearing the Design area (Design Grid)
8
Creating Queries – Using Comparison
Operators for Dates
• To Use a Comparison Operator in a Criterion
• Open the query in Design view
• Enter the criterion with a comparison operator
9
Sorting
10
Creating Queries – AND
11
Creating Queries – OR
12
Creating Queries – No Show
13
Creating Queries -- Wildcards
• To Create a query that asks for the condition as you run the
query, you should create a Parameter Query
• Type a question inside square brackets [ ] under the Criteria
row of the desired field (In this example, City)
• Run the query
• Type the desired condition
(In this example type
Granger)
• You should see the result
15
Removing Duplicates
• To Omit Duplicates
• After adding the desired
field, click an empty field
in the design grid
• Click the Property Sheet
button
• Click the Unique Values property box, and then click the arrow
that appears to produce a list of available choices
• Click Yes and run the query
16
Joining Tables
• To Join Tables
• Click the Query Design button to create a new query
• Add two related tables to the new query
• Add the desired fields from each table to the query
• To Change Join Properties
• Open the query in Design view
• Right-click the join line to produce a shortcut menu
• Click Join Properties on the shortcut menu to display the Join
Properties dialog box
17
Adding Criteria to a Join Query
18
Calculations – Calculated Fields
19
Calculations – Cont.
20
Caption
• To Change a Caption
• Open the query in Design view
• Click the field in the design grid to which you wish to add the
caption, and then click the Property Sheet button to display the
properties for the field
• Click the Caption box, and then type the desired caption
• Close the property sheet by clicking the property Sheet button
a second time
21
Functions or Statistics
• To Calculate Statistics
• Click the Totals button to include the Total row in the design
grid
• Add the field for which you
wish to total
• Click the Total arrow to display
the Total list
• Select the desired function
• After running the query, click
the Totals button again to
remove the Total row
22
Functions or Statistics – Cont.
23