Access 2010 Level 2 Unit 1Advanced Tables, Relationships, Queries, and Forms
description
Transcript of Access 2010 Level 2 Unit 1Advanced Tables, Relationships, Queries, and Forms
Contents© Paradigm Publishing, Inc. 1
Contents© Paradigm Publishing, Inc. 2
Access 2010
Level 2
Unit 1 Advanced Tables, Relationships,Queries, and Forms
Chapter 3 Advanced Query Techniques
Contents© Paradigm Publishing, Inc. 3
Advanced Query Techniques
Extract Records Using Select Queries Modify Join Properties in a Query CHECKPOINT 1 Create and Use Subqueries Select Records Using a Multiple-Value Field Perform Operations Using Action Queries CHECKPOINT 2
Quick Links to Presentation Contents
Contents© Paradigm Publishing, Inc. 4
Extract Records Using Select Queries
A select query is the type of query most often used in Access.
Select queries extract records from a single table or from multiple tables according to criteria that you specify.
Contents© Paradigm Publishing, Inc. 5
Extract Records Using Select Queries…continued
A filter is used in a datasheet or form to temporarily hide records that do not meet specified criteria. The subset of records can be edited, viewed, or printed.
A filter is active until it is removed or until the datasheet or form is closed.
Contents© Paradigm Publishing, Inc. 6
Extract Records Using Select Queries…continued
To save a filter as a query:1. Open the table.2. Filter the table as
desired.3. Click the Advanced Filter
Options button in the Sort & Filter group in the Home tab.
4. Click the Filter By Form option at the drop-down list.
continues on next slide…
Filter By Form option
Contents© Paradigm Publishing, Inc. 7
Extract Records Using Select Queries…continued
5. Click the Advanced Filter Options button in the Sort & Filter group in the Home tab.
6. Click the Save As Query option in the drop-down list.
continues on next slide…
Save As Query option
Contents© Paradigm Publishing, Inc. 8
Extract Records Using Select Queries…continued
7. At the Save As Query dialog box, type the desired query name.
8. Click OK.9. Close the Filter By Form
datasheet.10. Close the table. Save As Query
dialog box
Contents© Paradigm Publishing, Inc. 9
Extract Records Using Select Queries…continued
In a parameter query, specific criteria for a field are not stored with the query design. Instead, the field(s) used to select records have a prompt message that displays when the query is run.
Enter Parameter Value dialog box
Contents© Paradigm Publishing, Inc. 10
Extract Records Using Select Queries…continued
The message in the dialog box is created in the field to which the criterion will be applied.
When the query is run, the user types the criterion at the Enter Parameter Value dialog box. Access then selects the records based on that criterion.
If more than one field contains a parameter, Access prompts the user one field at a time.
Contents© Paradigm Publishing, Inc. 11
Extract Records Using Select Queries…continued
To create a parameter query:1. Start a new query in Design
view.2. Add the desired table(s).3. Close the Show Table dialog box.4. Add the desired fields to the
query design grid.5. Click in the Criteria row of the
field to be prompted.6. Type the message text, encased
in square brackets.7. Repeat Steps 5-6 for each
additional criteria field.8. Save the query.9. Close the query.
Criteria row
Contents© Paradigm Publishing, Inc. 12
Modify Join Properties in a Query
The term join properties refers to the way in which Access matches the values in the common fields between two tables in a relationship.
Access provides for three join types in a relationship: an inner join, a left outer join, and a right outer join.
Contents© Paradigm Publishing, Inc. 13
Modify Join Properties in a Query…continued
To create a query with an inner join:1. Create a new query in
Design view.2. Add the tables to the
query window.3. Double-click the join line
between the tables.4. At the Join Properties
dialog box, click OK.5. Add the desired fields to
the query design grid.6. Save and run the query.
Join Properties dialog box
Contents© Paradigm Publishing, Inc. 14
Modify Join Properties in a Query…continued
To create a query with a left outer join:1. Create a new query in
Design view.2. Add the tables to the
query window.3. Double-click the join line
between the tables.4. At the Join Properties
dialog box, click option 2.5. Click OK.6. Add the desired fields to
the query design grid.7. Save and run the query.
option 2
Contents© Paradigm Publishing, Inc. 15
Modify Join Properties in a Query…continued
To create a right outer join:1. Create a new query in
Design view.2. Add the tables to the
query window.3. Double-click the join line
between the tables.4. At the Join Properties
dialog box, click option 3.5. Click OK.6. Add the desired fields to
the query design grid.7. Save and run the query.
option 3
Contents© Paradigm Publishing, Inc. 16
Modify Join Properties in a Query…continued
To remove a table from a query:1. Open the query in
Design view.2. Right-click the table.3. Click the Remove
Table option at the shortcut menu.
Remove Table option
Contents© Paradigm Publishing, Inc. 17
Modify Join Properties in a Query…continued
To create a self-join query:1. Create a new query in
Design view.2. Add two copies of the
same table to the query.3. Right-click the second
table name.4. Click the Properties
option.continues on next slide…
Properties option
Contents© Paradigm Publishing, Inc. 18
Modify Join Properties in a Query…continued
5. Click in the Alias property box and delete the existing table name.
6. Type the alias table name.
7. Close the Property Sheet.
continues on next slide…
Alias property box
Contents© Paradigm Publishing, Inc. 19
Modify Join Properties in a Query…continued
8. Drag the field name from the left table to the field name in the right table that contains the matching values.
9. Add fields to the query design grid as required.
10. Run the query.11. Save the query.
field name
Contents© Paradigm Publishing, Inc. 20
Modify Join Properties in a Query…continued
If a query is created from two tables for which no join is established, Access will not know how to relate the records in each table.
In the absence of a relationship, Access produces a datasheet representing every combination of records between the two tables. This type of query is called a cross product or Cartesian product query.
If you add two tables to a query and no join line appears, create a join by dragging a field from one table to a compatible field in the other table.
Contents© Paradigm Publishing, Inc. 21
CHECKPOINT 11) This is the type of query most
often used in Access.a. appendb. selectc. updated. make-table
3) The Advanced Filter Options button is located in this tab.a. Homeb. Createc. External Datad. Database Tools
2) This is used to temporarily hide records that do not meet specified criteria.a. screenb. sectionc. filterd. sort
4) By default, Access uses this type of join between tables.a. innerb. outerc. leftd. right
Next Question
Next Question
Next Question
Next Slide
Answer
Answer
Answer
Answer
Contents© Paradigm Publishing, Inc. 22
Create and Use Subqueries
When performing multiple calculations based on numeric fields, you may decide to create a separate query for each individual calculation and then use subqueries to generate the final total.
A subquery is a query nested inside another query. Using subqueries to break the calculations into
individual objects allows you to reuse a calculated field in multiple queries.
Contents© Paradigm Publishing, Inc. 23
Create and Use Subqueries…continuedTo nest a query within a query:1. Start a new query in Design
view.2. At the Show Table dialog
box, click the Queries tab.3. Double-click the query to
be used as a subquery.4. Add other queries or tables
as required.5. Close the Show Table
dialog box.6. Add fields as required.7. Save and run the query.
Queries tab
Contents© Paradigm Publishing, Inc. 24
Select Records Using a Multiple-Value Field
To show a multiple-value field in separate rows in a query:1. Open the query in Design
view.2. Click in the Field list box of
the multiple-value field in the design grid.
3. Move the insertion point to the end of the field name.
4. Type a period.5. Press Enter to accept
the .Value property.6. Save the query.
Field list box
Contents© Paradigm Publishing, Inc. 25
Perform Operations Using Action Queries
Query Type Description
Make TableA new table is created from selected records in an existing table. For example, you could create a new table that combines fields from two other tables in the database.
AppendSelected records are added to the end of an existing table. This action is similar to performing a copy and paste.
UpdateA global change is made to the selected group of records based on an update expression. For example, you could increase the labor rate by 10 percent in one step.
Delete A selected group of records is deleted from a table.
Contents© Paradigm Publishing, Inc. 26
Perform Operations Using Action Queries…continued
To create a make-table query:1. Create the query in Design
view.2. Add the desired table to the
query.3. Add the desired fields to the
query design grid.4. Enter the criteria to select
records.5. Run the query.6. Switch to Design view.7. Click the Make Table button
in the Query Type group in the Query Tools Design tab.
continues on next slide…
Make Table button
Contents© Paradigm Publishing, Inc. 27
Perform Operations Using Action Queries…continued
8. Type a table name.9. At the Make Table
dialog box, select the destination database.
10. Click OK.11. Run the query.12. Click Yes.13. Save the query.
Make Table dialog box
Contents© Paradigm Publishing, Inc. 28
Perform Operations Using Action Queries…continued
A delete query is used to delete, in one step, a group of records that meet specific criteria.
You can use this action query in any instance in which the records you want to delete can be selected using a criteria statement.
Contents© Paradigm Publishing, Inc. 29
Perform Operations Using Action Queries…continued
To delete records using a query:1. Right-click the make-table
query.2. Click the Design View option
at the shortcut menu.3. Click the Delete button in the
Query Type group in the Query Tools Design tab.
4. Click the File tab.5. Click Save Object As.6. Type the name and click OK.7. Run the query.8. A the Microsoft Access
message, click Yes.
Microsoft Access message
Contents© Paradigm Publishing, Inc. 30
Perform Operations Using Action Queries…continued
To add records to a table using a query:1. Open the make-table query in
Design view.2. Click the Append button in the
Query Type group in the Query Tools Design tab.
3. At the Append dialog box, click OK.
4. Click the File tab.5. Click Save Object As.6. Type the name and click OK.7. Run the query.8. A the Microsoft Access
message, click Yes.
Append dialog box
Contents© Paradigm Publishing, Inc. 31
Perform Operations Using Action Queries…continued
To create an update query:1. Create the query in Design view.2. Add the desired table to the query.3. Add the desired fields to the query
design grid.4. Enter the criteria to select records.5. Run the query.6. Switch to Design view.7. Click the Update button in the Query
Type group in the Query Tools Design tab.
8. Click in the Update To box in the field to be changed.
9. Type the update expression.10. Run the query.11. Click Yes.12. Save the query.
Update To box
Contents© Paradigm Publishing, Inc. 32
CHECKPOINT 21) This is a query nested inside
another query.a. make-table queryb. update queryc. append queryd. subquery
3) This type of query is used to delete, in one step, a group of records that meet specific criteria.a. updateb. deletec. appendd. select
2) With this type of query, selected records are added to the end of an existing table.a. updateb. deletec. appendd. select
4) With this type of query, a global change is made to a selected group of records based on an expression.a. updateb. deletec. appendd. select
Next Question
Next Question
Next Question
Next Slide
Answer
Answer
Answer
Answer
Contents© Paradigm Publishing, Inc. 33
Advanced Query Techniques
Save a filter as a query Create and run a parameter query to prompt for criteria Add tables to and remove tables 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 multiple-value 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
Summary of Presentation Concepts