Lesson SummaryA Quick ReviewTo Create a Query in Design View: Click the Queries icon in the Objects bar, then double-click Create query in Design view. Select the table or query you want to use and click Add. Repeat as necessary for additional tables or queries that you want to add to the query and click Close when you're finished. Double-click the fields that you want to appear in the query or click and drag the fields onto the design grid. In the design grid, enter any desired search criteria for the field in the Criteria row and/or click the Sort box list arrow for the field and a sort order. Click the Save button on the toolbar, click Yes to save the query, enter a query name, and click OK. Understanding the Different Types of QueriesThe Types of Queries Are:
Creating a Multiple-Table QueryTo Create a Multiple-Table Query in Design View: Click the Queries icon in the Objects bar, then double-click Create query in Design view. Select the table or query you want to use and click Add. Repeat as necessary for additional tables or queries that you want to add to the query and click Close when you're finished. If Access doesn't automatically join the tables, click the related field in the first table and drag it to the related field in the second table. Repeat as necessary to connect all the tables. Double-click the fields that you want to appear in the query or click and drag the fields onto the design grid. In the design grid, enter any desired search criteria for the field in the Criteria row and/or click the Sort box list arrow for the field and select a sort order. Click the Save button on the toolbar, click Yes to save the query, enter a query name, and click OK. Creating a Calculated FieldTo Create an Expression or Calculation in a Query: Display the query in Design view. Click the Field row of a blank column in the design grid, enter the field name for the calculated field followed by a : (colon), then enter the expression you want Access to calculate, using the proper syntax (or you can use the Expression Builder to help you create this expression). Working with Expressions and the Expression BuilderTo Create an Expression with the Expression Builder: Display the query in Design view and click the Field row of a blank column in the design grid. Click the Build button on the toolbar, double-click the field you want to use in the calculation, click the button that corresponds to the calculation you want, and then click or type any other fields or values you want to use. Click OK when you're finished. Using an IIF FunctionTo Create an IIF (IF...THEN) Function: Display the query in Design view. Click the Field row of a blank column in the design grid, enter the field name followed by a : (colon) and type the expression using the syntax IIf(«expr», «truepart», «falsepart») (or you can use the Expression Builder to help you create the IIf expression). Summarizing Groups of RecordsTo Calculate or Summarize a Group of Records: Display the query in Design view and, if necessary, click the Totals button on the toolbar. Move the field that you want to group data by onto the design grid and make sure Group By appears in that field's Total row. Move the field that you want to perform calculations on onto the design grid. Choose the type of calculation that you want to perform by clicking the field's Total row, clicking the list arrow, and selecting a calculation from the list. Display Top or Bottom ValuesTo View Top or Bottom Values: Display the query in Design view, click the appropriate Sort field, and select either Ascending (displays bottom values) or Descending (displays top values). Select an option from the Top Values list on the toolbar. Parameter QueriesTo Create a Parameter Query: Display the query in Design view, click the Criteria row for the field you want to use for your parameter criteria and enter the text of the prompt, surrounded by square brackets [ ]. Finding Duplicate RecordsTo Use the Find Duplicates Query Wizard: In the Database window, click the Queries icon in the Objects bar and click the New button. Select Find Duplicates Query Wizard and click OK, then select the table or query you want to search and click Next. Double-click the field(s) that may contain the duplicate values and click Next. Double-click any additional fields that you want to appear in the query results, click Next, and then click Finish. Finding Unmatched RecordsTo Use the Find Unmatched Query Wizard: From the Database window, click the Queries icon in the Objects bar and click the New button. Select Find Unmatched Query Wizard and click OK, select the table whose values you want to display and click Next. Select the table that contains the related records, click Next, specify the related fields that join the two tables, then click the button to join the two tables and click Next. Double-click any additional fields that you want to appear in the query results, click Next, and then click Finish. Crosstab QueriesTo Create a Crosstab Query: In the Database window, click the Queries icon in the Objects bar and click the New button, then select Crosstab Query Wizard and click OK. Select the table or query you want to use in the crosstab query and click Next. Select the field you want to use as the row heading, click Next, select the field you want to use as the column heading, and click Next. Select the field you want to summarize, the type of calculation you want to use to summarize the field, click Next, type a name for the crosstab query, and click Finish. Delete QueriesTo Create a Delete Query: In the Database window, click the Queries icon in the Objects bar and click the New button. Select Design view and click OK. Add the appropriate tables and/or queries and click Close, then connect any unrelated tables. Click the Query Type button list arrow on the toolbar and select Delete Query or select Query View button to view the results of the delete query. If you're satisfied that the appropriate records will be deleted, click the Run button on the toolbar and click Yes to confirm the deletion. Append QueriesTo Create an Append Query: Create a new query, select Design view, and click OK. Click the tables and/or queries you want to use in the append query, click Add, and then click Close when you're finished. Click the Query Type button list arrow on the toolbar and select Append Query or select Query Query from the menu. Select the table to which you want to add the results of the query. If you select an existing table, click one of the following options: Current Database (if the table is in the currently open database) or Another Database (and type the name of the other database, including the path, if necessary). Click OK, then add the fields you want to append and identify a matching field if Access doesn't supply one. Click OK and click the View button on the toolbar to view the results of the query or the Run button on the toolbar to append the records. Make-Table QueriesTo Create a Make-Table Query: In Design view, create a select query; including any tables, fields, calculated fields, and criteria. Click the Query Type button list arrow on the toolbar and select Make-Table Query or select Query OK. Click the View button on the toolbar to view the results of the query or the Run button on the toolbar to create the new table. Update QueriesTo Create an Update Query: Create a new query in Design view, then select the tables and/or queries you want to use in the update query. Click the Query Type button list arrow on the toolbar and select Update Query or select Query View button to view the results of the update query. If you're satisfied that the appropriate records will be updated, click the Run button on the toolbar to update the records. Quiz
Homework
|