Advantages that a query design method has over using a datasheet view combined with filters

Andrew Couch shows you how to work with Queries in Microsoft Access 2013.

In this section:

  • Selecting individual columns from one or more tables

  • Joining tables to see unmatched or missing records

  • Filtering by single and multiple combinations of choices

  • Adding calculations with the expression builder

  • Returning the top matched records

  • Creating a summary calculation

  • Prompting to filter data with parameters

  • Creating a crosstab query with the Query Wizard

  • Simplifying a problem with a query by using other queries

Queries are where a database can offer a real benefit over a spreadsheet because they allow you to construct sophisticated, updatable presentations of your data. These can vary in complexity from a simple filtered list based on a single table to more complicated presentations of summarized information involving many tables of data. Remember that a database encourages you to split your data into separate tables to reduce duplication of information when you are entering data, at the expense of having that data in several places. You will see that queries lie at the very heart of a database and allow you to reassemble the data from the different tables into a single view with greater flexibility than if the data were in one list.

The power of queries increases as you gain more experience with Access. For example, layering one query on top of another allows you to break down a complex problem into several simple steps. A query can display data both from tables and from other queries. Queries can also be parameterized to prompt users to enter filtering criteria, and they can be extended so that they are driven by selections that you make in forms. (See “Linking a form to a query” on page 224.)

Selecting all columns from a table

A query allows you to choose information from one or more sources, which could be either tables or other queries, and link your choices together to present your final results. The query design tool offers several methods for selecting your fields.

One key choice in how you construct a query is whether it will automatically include any new changes, such as adding new fields to the underlying table. Using TableName.* ensures that a query will include all fields from the underlying table, at the expense of being less efficient because it might include fields that you do not intend to use. However, if additional fields are later added to the underlying table, they will be shown automatically in the query results.

Select all columns from a table

  1. Click the Create tab.

  2. Click Query Design.

  3. Click the table name in the Show Table popup window.

  4. Click Add.

  5. Close the Show Table popup window.

  6. Double-click the asterisk (*) to add all the columns to the query grid.

  7. Click View, and select Datasheet View.

Lesson 7: Sorting and Filtering Records

/en/access2016/working-with-forms/content/

Introduction

Access gives you the ability to work with enormous amounts of data, which means it can be difficult to learn anything about your database just by glancing at it. Sorting and filtering are two tools that let you customize how you organize and view your data, making it more convenient to work with. In this lesson, you'll learn how to sort and filter records.

Throughout this tutorial, we will be using a sample database. If you would like to follow along, you'll need to download our Access 2016 sample database. You will need to have Access 2016 installed on your computer in order to open the example.

Watch the video below to learn more about sorting and filtering records in Access.

About sorting and filtering

Essentially, sorting and filtering are tools that let you organize your data. When you sort data, you are putting it in order. Filtering data lets you hide unimportant data and focus only on the data you're interested in.

Sorting records

When you sort records, you are putting them into a logical order, with similar data grouped together. As a result, sorted data is often simpler to read and understand than unsorted data. By default, Access sorts records by their ID numbers. However, there are many other ways records can be sorted. For example, the information in a database belonging to a bakery could be sorted in a number of ways:

  • Orders could be sorted by order date or by the last name of the customers who placed the orders.
  • Customers could be sorted by name or by the city or zip code where they live.
  • Products could be sorted by name, category (like pies, cakes, and cupcakes), or price.

You can sort both text and numbers in two ways: in ascending order and descending order. Ascending means going up, so an ascending sort will arrange numbers from smallest to largest and text from A to Z. Descending means going down, or largest to smallest for numbers and Z to A for text. The default ID number sort that appears in your tables is an ascending sort, which is why the lowest ID numbers appear first.

In our example, we will be performing a sort on a table. However, you can sort records in any Access object. The procedure is largely the same.

To sort records:

  1. Select a field you want to sort by. In this example, we will sort by customers' last names.

    Advantages that a query design method has over using a datasheet view combined with filters

  2. Click the Home tab on the Ribbon, and locate the Sort & Filter group.
  3. Sort the field by selecting the Ascending or Descending command.

    Advantages that a query design method has over using a datasheet view combined with filters

  4. The table will now be sorted by the selected field.

    Advantages that a query design method has over using a datasheet view combined with filters

  5. To save the new sort, click the Save command on the Quick Access Toolbar.

    Advantages that a query design method has over using a datasheet view combined with filters

After you save the sort, the records will stay sorted this way until you perform another sort or remove the current one. To remove a sort, click the Remove Sort command.

Advantages that a query design method has over using a datasheet view combined with filters

Filtering records

Filters allow you to view only the data you want to see. When you create a filter, you set criteria for the data you want to display. The filter then searches all of the records in the table, finds the ones that meet your search criteria, and temporarily hides the ones that don't.

Filters are useful because they allow you to focus in on specific records without being distracted by the data you're uninterested in. For instance, if you had a database that included customer and order information, you could create a filter to display only customers living within a certain city or only orders containing a certain product. Viewing this data with a filter would be far more convenient than searching for it in a large table.

In our examples and explanations, we will be applying filters to tables. However, you can apply filters to any Access object. The procedure is largely the same.

To create a simple filter:

  1. Click the drop-down arrow next to the field you want to filter by. We will filter by city because we want to see a list of customers who live in a certain city.

    Advantages that a query design method has over using a datasheet view combined with filters

  2. A drop-down menu with a checklist will appear. Only checked items will be included in the filtered results. Clicking Select All will select or deselect everything at once. In our example, we'll deselect everything except Cary.

    Advantages that a query design method has over using a datasheet view combined with filters

  3. Click OK. The filter will be applied. Our customers table now displays only customers who live in Cary.

    Advantages that a query design method has over using a datasheet view combined with filters

Toggling your filter allows you to turn it on and off. To view the records without the filter, click the Toggle Filter command. To restore the filter, click it again.

Advantages that a query design method has over using a datasheet view combined with filters

Creating a filter from a selection

Filtering by selection allows you to select specific data from your table and find data that is similar or dissimilar to it. For instance, if you were working with a bakery's database and wanted to search for all products whose names contained the word chocolate, you could select that word in one product name and create a filter with that selection. Creating a filter with a selection can be more convenient than setting up a simple filter if the field you're working with contains many items. You can choose from the following options:

  • Contains includes only records with cells that contain the selected data.
  • Does Not Contain includes all records except for those with cells that contain the selected data.
  • Ends With includes only records whose data for the selected field ends with the search term.
  • Does Not End With includes all records except for those whose data for the selected field ends with the search term.

To create a filter from a selection:

  1. Select the cell or data you want to create a filter with. We want to see a list of all of our products that contain the word chocolate in their names, so we'll select the word Chocolate in the Product Name field.

    Advantages that a query design method has over using a datasheet view combined with filters

  2. Select the Home tab on the Ribbon, locate the Sort & Filter group, and click the Selection drop-down arrow.

    Advantages that a query design method has over using a datasheet view combined with filters

  3. Select the type of filter you want to apply. We'll select Contains "Chocolate" because we want to see records that contain the word Chocolate anywhere in the field.

    Advantages that a query design method has over using a datasheet view combined with filters

  4. The filter will be applied. Our table now displays only products with the word Chocolate in their names.

    Advantages that a query design method has over using a datasheet view combined with filters

Creating a filter from a search term

You can also create a filter by entering a search term and specifying the way Access should match data to that term. Creating a filter from a search term is similar to creating a filter from a selection.

Filtering text by a search term

When filtering text by entering a search term, you can use some of the same options you use when filtering by a selection, like Contains, Does Not Contain, Ends With, and Does Not End With. You can also choose from the following options:

  • Equals, which includes only records with data that is identical to the selected data
  • Does Not Equal, which includes all records except for the data that is identical to the selection
  • Begins With, which includes only records whose data for the selected field begins with the search term
  • Does Not Begin With, which includes all records except for those whose data for the selected field begins with the search term

To filter text by a search term:

  1. Click the drop-down arrow next to the field you want to filter by. We want to filter the records in our orders table to display only those that contain notes with certain information, so we'll click the arrow in the Notes field.

    Advantages that a query design method has over using a datasheet view combined with filters

  2. In the drop-down menu, hover your mouse over Text Filters. From the list that appears, select the way you want the filter to match the term you enter. In this example, we want to view only records whose notes indicate the order was placed for a party. We'll select Contains so we can search for records that contain the word party.

    Advantages that a query design method has over using a datasheet view combined with filters

  3. The Custom Filter dialog box will appear. Type the word you want to use in your filter.

    Advantages that a query design method has over using a datasheet view combined with filters

  4. Click OK. The filter will be applied.

    Advantages that a query design method has over using a datasheet view combined with filters

Filtering numbers with a search term

The process for filtering numbers with a search term is similar to the process for filtering text. However, different filtering options are available to you when working with numbers. In addition to Equals and Does not Equal, you can choose:

  • Greater Than to include only records with numbers in that field that are greater than or equal to the number you enter
  • Less Than to include only records with numbers in that field that are less than or equal to the number you enter
  • Between to include records with numbers that fall within a certain range

To filter numbers by a search term:

  1. Click the drop-down arrow next to the field you want to filter by. We want to filter the records in our menu items table by price, so we'll click the arrow in the Price field.
  2. In the drop-down menu, hover your mouse over Number Filters. From the list that appears, select the way you want the filter to match your search term. In this example, we want to see items that are less than $5, so we'll select Less Than.

    Advantages that a query design method has over using a datasheet view combined with filters

  3. The Custom Filter dialog box will appear. Type the number or numbers you want to use in your filter. We'll type 5 so the filter will show us only menu items that cost $5 or less.

    Advantages that a query design method has over using a datasheet view combined with filters

  4. Click OK. The filter will be applied.

    Advantages that a query design method has over using a datasheet view combined with filters

Specific types of numbers may include other filtering options. For instance, dates stored in numerical form (mm/dd/yyyy or 12/01/2013) include options to filter by periods of time.

Advantages that a query design method has over using a datasheet view combined with filters

Challenge!

  1. Open our practice database.
  2. Open the query called Cakes and Pies Sold.
  3. Apply a filter to the Product Types field that shows only Cakes.
  4. In the Sum of Quantity field, apply a number filter that only shows numbers greater than or equal to five.
  5. Apply an ascending sort to the Sum of Quantity field.

/en/access2016/designing-a-simple-query/content/

What advantages does the query method have over using filters?

Queries are slower it returns a calculated score of how well a document matches the query. Filters are faster because they check only if the document matched or not. Queries produce non-boolean values. Filters produce boolean values.

What are the benefits of using the query design method?

Using a query makes it easier to view, add, delete, or change data in your Access database..
Find specific quickly data by filtering on specific criteria (conditions).
Calculate or summarize data..
Automate data management tasks, such as reviewing the most current data on a recurring basis..

How do I filter a query design view in Access?

To filter data in a query, open it in Datasheet View, click the down-arrow at the top of a column, and select a filter option. Here's how it looks in an Access app: You can select multiple values from the list, but in an app, the filter list closes each time you select an option.

What is queries and filter in MS Access?

Filtering is a useful way to see only the data that you want displayed in Access databases. You can use filters to display specific records in a form, report, query, or datasheet, or to print only certain records from a report, table, or query.