| | Product Information Help and How-to Training Templates Support and Feedback Technical Resources Additional Resources | Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.
Create a select or crosstab query (MDB)
Create a select query Create a simple select query with a wizard
The Simple Select Query Wizard creates queries that retrieve data from the fields you specify in one or more tables or queries. If you want, the wizard can also sum, count, and average values for groups of records or all records, and it can calculate the minimum or maximum value in a field. However, you can't limit the records it retrieves by setting criteria (criteria: Conditions you specify to limit which records are included in the result set of a query or filter.).
- In the Database window (Database window: The window that appears when you open an Access database or an Access project. It displays shortcuts for creating new database objects and opening existing objects.), click Queries
under Objects, and then click New on the Database window toolbar.
- In the New Query dialog box, click Simple Query Wizard, and then click OK.
If the wizard doesn't start
- Follow the directions in the wizard dialog boxes. In the last dialog box, you can choose either to run the query or to see the query's structure in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).
If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view.
Create a select query on my own
- In the Database window (Database window: The window that appears when you open an Access database or an Access project. It displays shortcuts for creating new database objects and opening existing objects.), click Queries
under Objects, and then click New on the Database window toolbar.
- In the New Query dialog box, click Design View, and then click OK.
- In the Show Table dialog box, click the tab that lists the tables or queries whose data you want to work with.
- Double-click the name of each object you want to add to the query, and then click Close.
- Add fields to the Field row in the design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.), and if you want, specify criteria (criteria: Conditions you specify to limit which records are included in the result set of a query or filter.) and a sort order.
- To view the query's results, click View
on the toolbar.
Find duplicate records or field values in a table with a wizard
Using the Find Duplicates Query Wizard, you can create a select query (select query: A query that asks a question about the data stored in your tables and returns a result set in the form of a datasheet, without changing the data.) to determine if there are duplicate records in a table. For example, you might search for duplicate values in an Address field to determine if you have duplicate records for the same supplier, or you might search for duplicate values in a City field to see which suppliers are in the same city.
- In the Database window (Database window: The window that appears when you open an Access database or an Access project. It displays shortcuts for creating new database objects and opening existing objects.), click Queries
under Objects, and then click New on the Database window toolbar.
- In the New Query dialog box, click Find Duplicates Query Wizard, and then click OK.
If the wizard doesn't start
- Follow the directions in the wizard dialog boxes. If you don't choose to show fields in addition to those with duplicate values, the query results will sum the instances of each duplicate value. In the last dialog box, you can choose to run the query or see the query's structure in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).
If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view.
Find unmatched records between tables with a wizard
Using the Find Unmatched Query Wizard, you can create a select query (select query: A query that asks a question about the data stored in your tables and returns a result set in the form of a datasheet, without changing the data.) to find records in one table that don't have related records in another table. For example, you can find customers who don't have orders.
- In the Database window (Database window: The window that appears when you open an Access database or an Access project. It displays shortcuts for creating new database objects and opening existing objects.), click Queries
under Objects, and then click New on the Database window toolbar.
- In the New Query dialog box, click Find Unmatched Query Wizard, and then click OK.
If the wizard doesn't start
- Follow the directions in the wizard dialog boxes. In the last dialog box, you can choose to run the query or see the query's structure in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).
If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view.
Create a crosstab query Create a crosstab query with a wizard
- In the Database window (Database window: The window that appears when you open an Access database or an Access project. It displays shortcuts for creating new database objects and opening existing objects.), click Queries
under Objects, and then click New on the Database window toolbar.
- In the New Query dialog box, click Crosstab Query Wizard, and then click OK.
If the wizard doesn't start
- Follow the directions in the wizard dialog boxes. In the last dialog box, you can choose to run the query or see the query's structure in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).
If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view.
Create a crosstab query on my own
- In the Database window (Database window: The window that appears when you open an Access database or an Access project. It displays shortcuts for creating new database objects and opening existing objects.), click Queries
under Objects, and then click New on the Database window toolbar.
- In the New Query dialog box, click Design View, and then click OK.
- In the Show Table dialog box, click the tab that lists the tables or queries whose data you want to work with.
- Double-click the name of each object you want to add to the query, and then click Close.
- Add fields to the Field row in the design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.) and specify criteria (criteria: Conditions you specify to limit which records are included in the result set of a query or filter.).
- On the toolbar, click Query Type
, and then click Crosstab.
- For the field or fields whose values you want to appear as row headings, click the Crosstab row, and then click Row Heading.
You must leave the default Group By in the Total row for these fields.
- For the field whose values you want to appear as column headings, click the Crosstab row, and then click Column Heading. You can choose Column Heading for one field only, and you must leave Group By in the Total row for this field.
By default, the column headings are sorted in alphabetic or numeric order. If you want them to appear in a different order, or if you want to limit which column headings to display, set the query's ColumnHeadings property.
How?
You can change the order or limit the column headings in a crosstab query (crosstab query: A query that calculates a sum, average, count, or other type of total on records, and then groups the result by two types of information: one down the left side of the datasheet and the other across the top.). For example, in column headings containing the months of the year, you can display the months chronologically rather than alphabetically. Or, you can limit the columns to just January through June.
- Open the crosstab query in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).
- Click the background of query Design view, outside the design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.) and the field lists (field list: A window that lists all the fields in the underlying record source or database object, except in data access page Design view. In data access page Design view, it lists all the record sources and their fields in the underlying database.).
- On the toolbar, click Properties
to display the query's property sheet.
- In the ColumnHeadings property box, enter the column headings you want to display, in the order in which you want to display them. Between the column headings, type a comma or the list separator for your country/region. (To find the list separator for your country/region, see the regional settings in Microsoft Windows Control Panel.)
The column headings you enter must exactly match the column headings in the query datasheet. For example, if a column heading in the datasheet is "USA," you must enter a column heading of "USA" — not "US." (After you press ENTER or move the pointer to a different location, Microsoft Access places quotation marks around each heading.)
- To view the query's results, click View
on the toolbar.
Notes
- If you run a crosstab query often, or if you use it as the basis for a form, report, or data access page (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.), you can speed up the query by using the preceding procedure to specify fixed column headings.
- If you frequently use the same column headings in different queries, consider creating a table with one Text (Text data type: In a Microsoft Access database, this is a field data type. Text fields can contain up to 255 characters or the number of characters specified by the FieldSize property, whichever is less.) field to store the column headings. Then open the table and copy the headings into the ColumnHeadings property box as needed.
- For the field whose values you want to use in the cross-tabulation, click the Crosstab row, and then click Value.
Only one field can be set to Value.
- In the Total row for this field, click the type of aggregate function (aggregate function: A function, such as Sum, Count, Avg, or Var, that you use to calculate totals.) you want for the cross-tabulation (such as Sum, Avg, or Count).
- Do one of the following:
To view the query's results, click View
on the toolbar.
To stop the query after you start it, press CTRL+BREAK.
Notes
- The query Quarterly Orders by Product in the Northwind sample database is an example of a crosstab query (crosstab query: A query that calculates a sum, average, count, or other type of total on records, and then groups the result by two types of information: one down the left side of the datasheet and the other across the top.). To view this query, open the Northwind database in your Office folder's Samples folder, and then open Quarterly Orders by Product in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).
- If you include a field in the query design grid, but click the (Not Shown) option in the Crosstab cell and Group By in the Total cell, Microsoft Access groups on it as a Row Heading, but doesn't display the row in the query's results.
- The values in your Column Heading field may include characters usually not allowed in field names, such as decimals. If they do, Access replaces the character with an underscore in the datasheet.
Related Office Online discussionsRead related questions and answers from other Microsoft Office customers.
|