copyright 2007, paradigm publishing inc. backnextend 3-1 links to objectives save a filter as a...
TRANSCRIPT
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-1
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
ADVANCED QUERY TECHNIQUES
Microsoft Access 2007 – Level 2Microsoft Access 2007 – Level 2
Chapter 3Chapter 3
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-2
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Performance Objectives
• Save a filter as a query• Create and run a parameter query to prompt for
criteria• Add and remove tables to and from a query• Create an inner join, left join, and right join to modify
query results• Create a self-join to match two fields in the same table• Create a query that includes a subquery• Assign an alias to a table and a field name• Select records using a multi-valued field in a query• Create a new table using a make-table query• Remove records from a table using a delete query• Add records to the end of an existing table using an
append query• Modify records using an update query
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-3
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Save a Filter as a Query
1. Open the table and filter as desired
2. Click
then4. click
sam
e
3. Set desiredcriteria
5. Name the queryand click OK
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-4
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating a Parameter Query
Open a query in Design view;Open a query in Design view;type each prompt enclosed in square type each prompt enclosed in square brackets [ ] into a Criteria cell or fieldbrackets [ ] into a Criteria cell or field
Prompts for information when the query runs
Hint: make the prompt self-explanatory
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-5
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating a Parameter Query.../2
Run the query, responding to prompts
Type as directed by prompt and click OK
Query result – only those records that match both
(Case-insensitive)
Name and save the query as desired
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-6
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Modifying Joins in a Query
Relationships between tables may have been set in the Relationships window; those joins may
be overridden during a query
Create a query and show the desired tables; Access will insert a Join line as set up
1) in the Relationships window or
2) when creating Lookup fields
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-7
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Modifying Joins in a Query.../2
To change the Join, choose a different option in the Join dialog box
In query design, double-click the join line
Choose desired
option and click OK
Inner join
Left outer join
Right outer join
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-8
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Modifying Joins in a Query.../3
Example of an Inner Join
Only records that have matching fields in both tables will be
displayed
Notice missing records
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-9
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Modifying Joins in a Query.../4
Example of a Left Outer Join
All records from the primary table and those that match from the secondary
table
Notice nullfields
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-10
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Modifying Joins in a Query.../5
Example of a Right Outer Join
All records from the secondary table and those that match from the
primary table
Notice nullfields
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-11
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating a Self-Join
Joining Two Copies of the Same Table in a Query
Table must have matching values in two separate fields
1. Create Join line between fields
2. Insert fields from both tables into the grid
3. To change the name, right-click a field and choose Properties
4. Type into the Caption property
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-12
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
A Query with No Established Relationship
A query created from two tables with no join line produces a cross product or Cartesian product
query; it produces a datasheet with every combination of records between the two tables
Hint: Always review the join lines!
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-13
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating a Custom Calculation
A calculated field displays the result of an expression rather than displaying stored data
Enter an expression into an empty field cellin the query design grid
Enclose field names in bracketsCharacters before the
colon become the column name
Right-click the field cell to change its Format property
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-14
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating and Using Subqueries
A subquery is a nested query inside another query
Use for any combination of fields that will be used in multiple queries
Create and save the query to be nested
Create a new query and click the Show Table buttonAdd tables and queries as desired
Be sure to review the joins!
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-15
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Query with a Multi-Valued Field
In query design, determine how the multi-valued field should be displayed
Table containing the multi-value field has two entries for the field
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-16
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating an Alias for a Table or Field
Can change the table name for use in a query without changing it for all other objects (queries,
forms, reports, etc.)In query design view,right-click the table and choose Properties
Remove the existing Alias text
and type the desired alias
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-17
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating an Action Query
To perform an operation on a selected group of records
Action Query Description
Make Table Creates a new table from selected data in one or more other tables
Delete Deletes selected records from one or more tables
Append Copies selected records from one or more tables to the end of one or more tables
Update Makes changes to selected records from one or more tables
Caution! After running an action query, its action cannot be undone!
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-18
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating an Action Query…/2
Steps to creating and running an action query
1. Build and run a select query with tables, fields, criteria, and sort order
2. Change the query type
3. Run the action query once only
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-19
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating a Make-Table Query
Enter thetable name
Click
Choose the current oranother database andname it or Browse
In Query Design view, after creating a Select query to verify the records, click the Make Table button
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-20
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating a Make-Table Query…/2
Review the message and click Yes
Click the Run button to perform the query
then Save and close the query
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-21
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating a Delete Query
Read the message and click Yes
Click the Run button to run the query
In Query Design view, after creating a Select query to verify the records, click the Delete button
The View button previews records to be deleted;
the Run button deletes the records permanently
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-22
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating an Append Query
Enter thetable name
Click
Choose the current oranother database andname it or Browse
In Query Design view, after creating a Select query to verify the records, click the Append button
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-23
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating an Append Query.../2
Review the message and click Yes
Click the Run button to perform the query
Save and close the query
The query and the receiving table must have the same structure
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-24
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating an Update Query
In the new row, in the column to be updated,enter the text orexpression thatwill replace the contents of thisfield
In Query Design view, after creating a Select query to verify the records, click the Update button
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-25
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Creating an Update Query…/2
Review the message and click Yes
Click the Run button to perform the query
Save and close the query
The update expression must have the same data type as the original field
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-26
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
How do you save a filter as a query?
Features Summary
1. After filtering as desired
2. Click
then4. click
3. Review criteria
5. Name the queryand click OK
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-27
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
How do you create a parameter query?
Features Summary
Open a query in Design view;Open a query in Design view;type each prompt enclosed in square type each prompt enclosed in square
brackets [ ] into a Criteria cell or fieldbrackets [ ] into a Criteria cell or field
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-28
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
How do you join two tables so that all the records in the primary table will display?
Features Summary
Choose Left outer
join
In query design, double-click the join line
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-29
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
How do you join two tables to display only the records that match between the primary and secondary tables?
Features Summary
In query design, double-click the join line
ChooseInner join
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-30
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
How do you create a new table from selected records in an existing table?
Display the records with a Select query, then change the query to a
Make Table query
Features Summary
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-31
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3
How do you add records from one table to the end of another table?
Features Summary
Display the records with a Select query, then change the query to an
Append query
Copyright 2007, Paradigm Publishing Inc.
BACK NEXT END
3-32
LINKS TO OBJECTIVES• Save a Filter as a Que
ry• Parameter Query• Inner, Left, and Right
Joins• Self-Join• Calculated Field• Query with a
Subquery• Table Alias• Multi-valued Field in
a Query• Action Queries• Make-Table Query• Delete Query• Append Query• Update Query• Features Summary
ACCESS 2007Chapter 3 Coming Next
CREATING AND USING CUSTOM FORMS
Chapter 4Chapter 4