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.

  1. To construct a query, Click on the New button in the database window as shown in Figure 16. Choose Design View, click OK.
  2. figure16 Figure 16

  3. 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.
  4. figure17 Figure 17

  5. 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.
  6. figure18 Figure 18

  7. Enter the criteria for the query in the Criteria field. The Expression Builder image5 can also be used to assist in writing the expressions in the Criteria field.
  8. After you have selected all of the fields and tables, click the Run image6 button on the toolbar to execute the query. Figure 19 shows the query result: records that match the criteria you set.
  9. figure19 Figure 19

  10. Choose Save from the File menu to save a query for later execution.

next section >