Query with Two Related Tables
Query with Two Related Tables
An obvious deficiency in the previous queries is that the people associated with an expense or a sale are only identified by the value of the PeopleID field in the People table. Adding their names to the query output is simple because we have established relations between the People table and the Expenses and Sales tables. We will make a new query that displays sales information along with the name of the associated person.
Step 1: Start the query in Design View
From the main Base window, click Queries in the left pane and then Create Query in Design View from the Tasks pane.
Step 2: Add tables to the query
In the Add Query or Table dialog, click on People and then the Add button and do the same for the Sales table. Click Close. You will now have small representations of the two tables with a line running from the PeopleID field of one to the PersonID field of the other, as shown in Figure 196. You may want to resize the tables by dragging down their lower edges.
Step 3: Add fields to the query
Double-click on the FirstName and LastName from the People table and Date and Amount from the Sales table to add them to the query definition table.
We now have a query that will display the names along with the information from the Sales table. Save both the query and the main Base document. The query can be enhanced with criteria in any column or with calculated columns as shown in the previous sections.
Content on this page is licensed under the Creative Common Attribution 3.0 license (CC-BY). |