Office 2019 For Dummies
Book image
Explore Book Buy On Amazon
One problem with sorting or filtering an Access database table is that you must constantly define what you want to sort or filter. If you sort or filter your data a certain way on a regular basis, use a query to search an Access database instead.

A query is nothing more than a saved version of your Access sort or filter criteria. By saving the particular Access sort or filter criteria as a query, you can select that query by name later.

Creating a simple query in Access 2019

If your database table contains dozens of different fields, you may find it confusing to make sense of all your information. As an aid, a simple query strips away fields so you see only the fields containing data you want to see, such as a person’s name and phone number but not her hire date or employee number.

To create a MS Access query, follow these steps:

  1. Click the Create tab.
  2. In the Queries group, click the Query Wizard icon.

    The New Query dialog box appears.

    New Query Access 2019 The New Query dialog box lets you choose a Query Wizard.
  3. Click Simple Query Wizard and then click OK.

    The Simple Query Wizard dialog box appears.

    Access Simple Query Wizard The Simple Query Wizard dialog box lets you pick the fields to use for your query.
  4. In the Available Fields box, click a field name listed, and then click the > button.

    Access displays your chosen field in the Selected Fields box.

  5. Repeat Step 4 for each field you want to use in your query.
  6. Click Next.

    If any of your chosen fields contains numeric data, another dialog box appears. This dialog box asks whether you want to display your data in a Detail view (shows every record) or Summary view (shows numerical information such as the total number of records found, the average value, and the minimum/maximum value).

    choose Accss view Choose between Detail or Summary view.
  7. Select the Detail or Summary radio button and then click Next.

    Another dialog box appears, asking you to type a descriptive name for your query.

  8. Click in the text box, type a descriptive name for your query, and then click Finish.

    Access displays the results of your query as a separate tab. If you add information to or delete information from your database, you can click this query tab to get a quick look at the results of your query without defining everything all over again.

  9. To save your query, click the File tab, and then choose the Save icon.

    Access saves your query in the All Access Objects pane under the Queries category. Any time you want to view that query, just double-click it.

Creating a crosstab query in Access 2019

A crosstab query lets you combine two or more fields to calculate and display a calculation based on a third field. For example, if your Access database contains the names of salespeople and the products they sold, you can use those two fields to create a crosstab that tells you how much each salesperson sold of each product.

Access crosstab query A crosstab query extracts information by cross-referencing two or more fields.

The Crosstab Query Wizard lets you define up to three fields in a crosstab query, but you can always add more fields manually in the Design view.

To create a crosstab query in Access, you need to identify three types of fields:
  • One to three fields to identify each record (such as the First Name and Last Name fields)
  • A single field to display specific data from each record (such as the Product field, which displays the product names Purses, Unicorns, or Missiles)
  • A crosstab field that displays a calculated result (such as Sales)
To create a crosstab query in Access, follow these steps:
  1. Click the Create tab.
  2. In the Queries group, click the Query Wizard icon.

    The New Query dialog box appears.

  3. Click the Crosstab Query Wizard and then click OK.

    The Crosstab Query Wizard dialog box appears.

    Crosstab Query Wizard Access The Crosstab Query Wizard dialog box asks you to choose which database table to use.
  4. Click a database table and then click Next.

    Another Crosstab Query Wizard dialog box appears that asks for between one and three fields to identify each row (record).

    crosstab query Access 2019 The first step to creating a crosstab query is to choose up to three fields to identify each record.
  5. In the Available Fields box, click a field and then click the > button to move your chosen field to the Selected Fields box.
  6. Repeat Step 5 for each additional field you want to include.
  7. Click Next.

    Another dialog box appears, asking for a single field to use to cross-tabulate data with the fields you chose in Steps 5 and 6.

    cross-tabulate Access To cross-tabulate your data, you need to choose another field.
  8. Click a field name and then click Next.

    Ideally, this field should consist of text information that lists different data, such as sales regions (East, West, North, or South) or products (Missiles, Unicorn, and so on). If you choose a field that contains numerical data, your crosstab query displays only those numbers in the column headings, which will seem meaningless. Another dialog box appears.

    Crosstab Query Wizard Access The Crosstab Query Wizard dialog box displays a list of mathematical functions you can choose from.
  9. In the Fields box, click a field and then click a mathematical function that you want Access to calculate, such as Sum, Avg, or Count.
  10. Click Next.

    Another dialog box appears, asking for a name for your query.

  11. In the text box at the top of the dialog box, type a descriptive name for your query and then click Finish.

    Access displays your crosstab query.

    Crosstab Query calculations The Crosstab Query can display calculations on your database information.
  12. To save your query, click the File tab and choose the Save icon.

Creating a query that finds duplicate field data

Suppose you sell a hundred different products. How can you tell which products customers are buying the most? To find the answer to this type of question, you can search your database manually to find a Products Sold field and then count how many times each product appears.

As a simpler solution, you can create a MS Access query that finds and counts how many times duplicate data appears. To create a query to find duplicate field data in Access, follow these steps:

  1. Click the Create tab.
  2. In the Queries group, click the Query Wizard icon.

    The New Query dialog box appears.

  3. Click Find Duplicates Query Wizard, and then click OK.

    The Find Duplicates Query Wizard dialog box appears, asking you to choose the database table to search.

  4. Click a database table and then click Next.

    Another dialog box appears, asking you to choose the fields to examine for duplicate data.

  5. Click a field name and then click the > button. Repeat this step for each additional field you want to search.
  6. Click Next.

    Another dialog box appears, asking whether you want to display additional fields. If you choose to look for duplicate data in a Product field (Step 5) to see which products are most popular, you can display additional fields such as each salesperson’s name so you can also see who is responsible for selling the most products.

  7. Click a field and then click the > button. Repeat this step for each additional field you want to display.
  8. Click Next.

    A dialog box appears, asking whether you want to give your query a descriptive name.

  9. In the top text box, type a descriptive name and then click Finish.

    Access displays your query as a separate tab.

  10. To save your query, click the File tab and then choose the Save icon.

Creating an unmatched query in Access 2019

Access can store huge amounts of data, but the more data you store, the harder it can be to view it. To help you organize your data, you can divide it into separate tables. For example, one table might contain a list of customers, and a second table might contain a list of salespeople.

When you store data in separate tables, each table may share one or more common fields. For example, a table containing customers may contain a SalesPerson field that shows which salesperson deals exclusively with which customer. A second table listing salespeople can contain the Customer field (along with additional information, such as each salesperson’s phone number, address, sales region, and so on).

An unmatched query examines two (or more) database tables to look for missing information. For example, you can use an unmatched query to find customers who haven’t ordered anything in the past six months, sales regions that haven’t ordered certain products, or salespeople who have not been assigned to a sales region. Basically, an unmatched query can help you find missing pieces or holes in your entire database file.

To create an unmatched query in Access, follow these steps:

  1. Click the Create tab.
  2. In the Queries group, click the Query Wizard icon.

    The New Query dialog box appears.

  3. Click Find Unmatched Query Wizard, and then click OK.

    The Find Unmatched Query Wizard dialog box appears, asking you to choose a database table that contains the unmatched records you want to find.

  4. Click a database table and then click Next.

    Another dialog box appears, asking you to choose a database table that contains at least one field that also appears in the table you chose in Step 3.

  5. Click a second database table and then click Next.

    Another dialog box appears, asking you to identify the field that both database tables have in common.

  6. Click the common field that both database tables share.
  7. Click the gray <=> button that appears between the two fields and then click Next.

    A dialog box appears, asking you to identify the fields you want to display from the database table you chose in Step 4.

  8. Click a field and then click the > button. Repeat this step for each additional field you want to display.
  9. Click Next.

    A dialog box appears, asking you to give your query a descriptive name.

  10. In the text box, type a descriptive name and then click Finish.

    Access displays your query results, which show you only the data in fields you selected in Step 8.

  11. To save your query, click the File tab and choose the Save icon.

Viewing, renaming, closing, and deleting Access queries

Each time you create and save a query, Access stores it for future use. After you create and save a query, you can add or delete data from your tables and then apply your queries on the newly modified data.

To view a query, just double-click the query name in the left pane. In case you need to rename your query to give it a better descriptive name, follow these steps:

  1. Right-click the query name in the left pane.

    A pull-down menu appears.

  2. Choose Rename.

    Access highlights the query name.

  3. Type a new name and then press Enter.
Each time you view a query, it displays a tab. Eventually, you’ll probably want to get rid of a query, so to close a query, follow these steps:
  1. Right-click the query name that appears in the tab.

    A pull-down menu appears.

  2. Choose Close.

    Access closes your chosen query and removes its tab from view.

Queries can be handy, but eventually, you may no longer need a query. To delete it, follow these steps:
  1. Right-click a query name and choose Delete from the pop-up menu that appears.

    You won't be able to delete a query unless you close it first.

    A dialog box appears, asking whether you really want to delete your query.

  2. Click Yes (or No).

About This Article

This article is from the book:

About the book author:

Wallace Wang is the bestselling author of more than 50 computer books, with over three million of his For Dummies books in print. They include numerous versions of Office For Dummies as well as Beginning Programming For Dummies. When not playing with computers, Wallace splits his time between teaching, writing, game designing, screenwriting, and stand-up comedy.

This article can be found in the category: