Presentation is loading. Please wait.

Presentation is loading. Please wait.

New Perspectives on Microsoft

Similar presentations


Presentation on theme: "New Perspectives on Microsoft"— Presentation transcript:

1 New Perspectives on Microsoft
Microsoft Access 2002 Tutorial 8 – Using Query Wizards and Action Queries, and Defining Table Relationships New Perspectives on Microsoft Access 2002 Tutorial 8

2 Create a crosstab query
A crosstab query performs aggregate function (arithmetic operations) calculations on the values of one database field and displays the results in a spreadsheet format. There are a variety of functions that can be used in crosstab queries including average, count, first field value, last field value, etc. Excel provides a Crosstab Query Wizard that will walk you through the creation of the crosstab query. New Perspectives on Microsoft Access 2002 Tutorial 8

3 Crosstab query aggregate functions
The figure below shows the aggregate functions that can be used in a crosstab query. New Perspectives on Microsoft Access 2002 Tutorial 8

4 A select query versus a crosstab query
This figure shows a Select query and a crosstab query. These two queries are based on the same data. In this case the crosstab query is using the Sum function to summarize the potential income for each country. However, notice that the crosstab query data is much more summarized than the select query data. New Perspectives on Microsoft Access 2002 Tutorial 8

5 The Crosstab Query Wizard steps
First: select the table or query upon which you want to create the crosstab query. Second: select the fields that will be used for the row headings. Third: select the field that will be used for the column headings. Fourth: select the field that will be calculated upon and what calculation is to be performed. In the list of queries, crosstab queries will have a special icon that will identify them as such. New Perspectives on Microsoft Access 2002 Tutorial 8

6 The final Crosstab Query Wizard dialog box
This figure shows the final Crosstab Query Wizard dialog box where you select the field to be used for the calculation, and which type of calculation to perform. New Perspectives on Microsoft Access 2002 Tutorial 8

7 Create a find duplicates query
A find duplicates query is a select query that locates duplicate records in a table or query. The Find Duplicates Wizard will help you make selections about the field(s) for which you want to find duplicates. Use this type of query to locate duplicates that create potential problems in your database, such as assigning two different product numbers to the same product. New Perspectives on Microsoft Access 2002 Tutorial 8

8 A sample find duplicates query datasheet
The following figure shows a “find duplicates” query datasheet. Notice that this datasheet includes records for employers that have multiple positions available (i.e., the employer appears more than once in the underlying table). New Perspectives on Microsoft Access 2002 Tutorial 8

9 Create a find unmatched query
You can also create a find unmatched query, which returns a datasheet for all records that do not have a matching record in the related table. This figure shows the third dialog box of the Unmatched Query Wizard. Notice that on this dialog box, you will select which fields in each table for which you are checking for unmatched records. New Perspectives on Microsoft Access 2002 Tutorial 8

10 Create a top values query
You can use the Top Values query to display a specified number of records. Specify a number indicating the number of records to display or specify a percentage indicating the percentage of the records to display. For example, you could specify 20 percent, which would produce a resulting a datasheet displaying only 20 percent of the records The Top Values button on the query design toolbar will allow you to select from a list or to enter your own value for the Top Values query. New Perspectives on Microsoft Access 2002 Tutorial 8

11 Setting the top value query value
In the figure below, you can see that the Top Values list box has been set to 25 percent. This means that the resulting query will display the highest 25 percent of potential income amounts. New Perspectives on Microsoft Access 2002 Tutorial 8

12 The top value query datasheet
The following figure is the result of the query design shown in the preceding figure. New Perspectives on Microsoft Access 2002 Tutorial 8

13 New Perspectives on Microsoft
Create action queries You can create other types of queries that make changes to the data in the underlying table(s). Action queries can: Create a new table (make-table query) Add records to a table (append query) Delete records from a table (delete query) Update the data in a table (update query) New Perspectives on Microsoft Access 2002 Tutorial 8

14 Action query considerations
When creating a query that actually makes changes to your database, take extreme care that you do not create a query that performs unintended actions. It is a good idea to create your action query first as a select query. You can then view the results and determine if these are the records you want to alter. When you are sure the query will be applied to the records you really want, you can then run the query as an action query. New Perspectives on Microsoft Access 2002 Tutorial 8

15 Use make-table and append query queries
To change a select query to a Make Table query, choose Make-Table Query from the Query Type button's list. This will open the Make Table dialog box, in which you will specify the name of the new table. To change a select query to an append query, choose Append Query from the Query type button's list. In the Append Query dialog box, you will specify to which table you want to append records. The Append To row will be displayed in the design grid indicating the fields that the query will append to the table. New Perspectives on Microsoft Access 2002 Tutorial 8

16 The Make Table dialog box
The Make Table dialog box is used to create a make table query, which creates a new table from an existing table. New Perspectives on Microsoft Access 2002 Tutorial 8

17 The query window for an append query
This figure shows the query window for an append query. The Append To row shows the fields that the query will append to the specified table. New Perspectives on Microsoft Access 2002 Tutorial 8

18 Apply an advanced filter in a table
You can create advance filters that allow you to specify multiple selection criteria and to specify a sort order for the selected records. The Advance Filter window looks very similar to a query design window and works in a similar manner. You add the fields to the design grid for which you want to specify selection criteria and/or sorting specifications. Once you have added the criteria you want for your filter, you can apply the filter by pressing the Apply Filter button. You can also remove the filter by pressing the Remove Filter button. New Perspectives on Microsoft Access 2002 Tutorial 8

19 New Perspectives on Microsoft
The Filter window In the Filter window, you select only the fields that will be involved in the filtering and sorting specifications. The Filter window works very much like the query design grid. You can specify filtering and sorting criteria for the Advanced Filter. New Perspectives on Microsoft Access 2002 Tutorial 8

20 Define many-to-many and one-to-one relationships between tables
A many-to-many relationship exists between tables when the tables involved have multiple matches in each of the tables. For example, if you have a table containing student data and another table containing course data, you could say that this is a (M:N) relationship because a student can take many courses and a course can have many students Whenever there is a many-to-many relationship, you must provide a third table that will “link” the two tables together in a one-to-many relationship. You can also have a one-to-one relationship between tables, which means that there is exactly one record in the primary table that matches exactly one record in the related table. New Perspectives on Microsoft Access 2002 Tutorial 8

21 A many-to-many relationship
In the figure below, you see an illustration of a many-to-many relationship. Note that the Job table is used to join the Position table and the Student table. The Job table contains a PositionID and a StudentID for each position that a students holds. In this case, a student can have more than one position and a position can be held by more than one student. New Perspectives on Microsoft Access 2002 Tutorial 8

22 A query datasheet for a many-to-many relationship
Once you have created the third table (the table that joins the two tables in a many-to-many relationship) you can create a query based on all three tables. The following figure show a query datasheet based on the three tables. New Perspectives on Microsoft Access 2002 Tutorial 8

23 View and create indexes to tables
When you establish a primary key for a table, you are actually creating an index for the table. An index is a list that relates field values to the records that contain those field values. The index makes it faster to search for records and to sort the records in a table. You can view existing indexes in table design view by clicking on the Indexes button on the Table Design toolbar. New Perspectives on Microsoft Access 2002 Tutorial 8

24 New Perspectives on Microsoft
How indexing works You can create an index on any field in a table. However, each index actually is a new file and takes up space When records are entered into a table they are assigned an internal record number in the order they were entered. The index created a different ordering of the records but keeps track of the number originally assigned to the record. New Perspectives on Microsoft Access 2002 Tutorial 8

25 An illustration of an index
In the figure below, you can see a graphical representation of the use of an index in the Position table. In this example, the index on the PositionID field (primary key) is in ascending order and an additional field, the Record Number field, maintains the assigned record number. New Perspectives on Microsoft Access 2002 Tutorial 8

26 New Perspectives on Microsoft
The Indexes window This figure shows the Indexes window, which can be used to view index information. New Perspectives on Microsoft Access 2002 Tutorial 8

27 Join a table using a self-join
There are three types of joins: The inner join selects records from two tables only when the records have the same value in the common field that links the tables. A left outer join selects all records from the first, or left, table and only those records from the second, or right, table that have matching common field values. A right outer join selects all records from the second, or right, table and only those records from the first, or left, table that have matching common field values. A self-join can be either an inner or outer join and is used to join a table to itself. New Perspectives on Microsoft Access 2002 Tutorial 8

28 An example of an inner join
In this figure you see an example of an inner join. Notice that the resulting datasheet includes only those records that have matching StudentID fields in the two tables. New Perspectives on Microsoft Access 2002 Tutorial 8

29 An example of a left outer join
The next figure shows an example of a left outer join. Notice that the resulting datasheet includes all the records from the Student table and only those records from the Job table that have a matching record in the Student table. New Perspectives on Microsoft Access 2002 Tutorial 8

30 An example of a right outer join
This figure is an example of a right outer join. In this case, the resulting datasheet contains all the records from the Job table and only those records from the Student table that have a matching record in the Job table. New Perspectives on Microsoft Access 2002 Tutorial 8

31 An example of a self-join
This figure shows the datasheet for a self-join. New Perspectives on Microsoft Access 2002 Tutorial 8


Download ppt "New Perspectives on Microsoft"

Similar presentations


Ads by Google