Creating Queries
A query is simply a question you ask a database. How many books are written by a certain author? Who wrote a book in a certain year? Queries select records from one or more tables in a database that match the criteria you set. They can be viewed, analyzed, and sorted on a common datasheet. The resulting collection of records, called a dynaset (short for dynamic subset), is saved as a database object and can therefore be easily used in the future. The query will be updated whenever the original tables are updated.
- To construct a query, Click on the New button in the database window as shown in Figure 16. Choose Design View, click OK.
- In the Show Table dialogue box as shown in Figure 17, you will be asked to choose a table/tables for the query. Select the tables you want to query and click Add.
- Add fields from the tables to the new query by double-clicking the field name in the table boxes or selecting the field from the Field and Table drop-down menus on the query form as shown in Figure 18. Specify sort orders if necessary.
- Enter the criteria for the query in the Criteria field. The Expression Builder
can also be used to assist in writing the expressions in the Criteria field. - After you have selected all of the fields and tables, click the Run
button on the toolbar to execute the query. Figure 19 shows the query result: records that match the criteria you set. - Choose Save from the File menu to save a query for later execution.
Figure 16
Figure 17
Figure 18
Figure 19
