
- •Using Data Filters
- •Filter by Selection
- •To Do: Perform a Filter by Form
- •Using Queries
- •Creating a Query with the Query Wizard
- •To Do: Build a Query with the Simple Query Wizard
- •Using the Query Design View
- •To Do: Create a Query from Scratch
- •To Do: Work with Complex Queries
- •Table 19.1. Access's Relational Operators
- •Summary
- •If I save a filter as a named query, what does the query's Query Design view look like?
Using the Query Design View
When you create or edit a query from scratch, you can use the Query Design view (such as the one shown in Figure 19.4).
Figure 19.4 The Query Design view enables you to create powerful queries.
Although the Query Design view looks somewhat strange at first, the view's design is logical. The top of the Query Design view contains the source tables and queries, and the bottom of the Query Design view displays the criteria (the query-selection commands).
You use the Query Design view when you must
Create an advanced query that the query wizards cannot create.
Edit an existing query.
After you learn to create a query with the Query Design view, you will also understand how to use the Query Design view to edit existing queries.
To Do: Create a Query from Scratch
To use the Query Design view to create a query, follow these steps:
Select Queries in the Database window.
Click the New button to open the New Query dialog box.
Select Design View and click OK to open the Query Design view. Access displays the Show Table dialog box that contains all your table and query details (similar to the one shown in Figure 19.5).
Figure 19.5 Select from your database's tables and queries for the new query.
Click the table or tables that you want to include in the query and then click Add. As you add tables to the query, Access displays a new table in the Query Design view showing in the background. If you want to base your new query on another query, click the Queries tab to display a list of them from which you can choose and then add the selected query. If you want to add both tables and queries, click the Both tab to display all your database tables and queries and then select the ones you need.
Click Close to close the Show Table dialog box.
You have yet to build the entire query, but you have selected tables, existing queries, or both on which to base your new query. Next, enter the query's criteria so that Access knows which records and fields to select from your tables and existing queries.
Note
It's easy to accidentally add the same table twice to a query. If you do, just click the "extra" table in the upper pane of the query and press Delete.
Figure 19.6 shows the start of a new query. This query extracts from two tables, one named Customers and one named Employees. The line connecting the tables' common field, City, appears when you drag your mouse between the common field, as you do when you want to create a relationship. You might recall from the preceding section that Access must base queries on related tables and queries, and the common field relates the two tables.
Figure 19.6 This query can now extract from two related tables.
Note
Think of the top half of the query's design window as starting the request, "Given these tables and queries&hellip" and the lower half of the window as finishing that request, "…extract all data that meets these conditions." The Query Design view contains your instructions when you want Access to extract data from one or more tables or queries and display the result in a table subset.
Each column in the Query Design view's lower half contains the resulting query's fields. Therefore, if you want the resulting data subset to contain four fields, you fill in four of the Query Design view's lower columns. These columns contain the instructions that indicate to the query how to extract the data from the table, tables, query, queries, or combinations of tables and queries that you have specified for the query.