Introduction
While tables store your data, the true analytical power of a relational database is revealed through the query. Have you ever wondered how a business can instantly isolate a list of high-value customers from a database containing thousands of records? Queries allow you to retrieve and compile information from one or more tables based on specific, logical conditions you define. In this lesson, you will learn the fundamental steps to construct a one-table query, turning raw data into actionable insights.
Watch the video below to master the architectural logic of simple queries.
What are queries?
At its core, a query is a sophisticated search tool. Running a query is akin to asking your database a detailed question. By defining specific search conditions, you instruct Access to sift through your data and present only the information that meets your requirements.
How are queries used?
Queries are significantly more robust than basic table filters. Their unique advantage is the ability to synthesize information from multiple tables simultaneously. For instance, while a search might find a customer's name, a query can link that customer's name to their specific purchase history from a separate table. A well-constructed query uncovers connections that are not immediately visible by simply browsing through data rows.
To build these logical structures, Access utilizes a specialized environment known as Query Design view. This view acts as the blueprint for your data retrieval logic.
Interact with the buttons below to explore the professional tools available in Query Design view.
View Options
Switch between Datasheet view (to see results) and Design view (to modify logic).
Run Query
Executes your logic and populates the results into a readable table.
Object Relationship Pane
Windows representing each table in your query, showing all available fields.
Fields and Tables
Identifies exactly which fields are included and the specific table they originate from.
The Design Grid
The workspace where you define the criteria and filtering rules for the query.
Sorting
Dictates whether the results appear in Ascending or Descending order.
Show/Hide Fields
Allows you to use a field for logic without making it visible in the final results.
Query Criteria
Specify the exact values you are searching for (e.g., "Raleigh" or ">5").
One-table queries
To understand the workflow of query building, we will start with a one-table query. This is essentially an advanced filter that allows for more complex logic than standard datasheet filtering.
Scenario: Imagine our bakery is hosting an event. We need to identify customers who live in Raleigh or within the 27513 zip code. By using two criteria simultaneously, we can generate a targeted mailing list for our invitations.
To create a simple one-table query:
- Select the Create tab on the Ribbon and click the Query Design command.
- In the Show Table dialog, select the Customers table and click Add, then Close.
- Double-click the field names you require (e.g., First Name, Last Name, City, Zip Code) to add them to the design grid.
- Defining Logic:
- To find records meeting *both* criteria, type them on the same Criteria: row.
- To find records meeting *either* criteria, type the first in the Criteria: row and the second in the or: row.
- Click the Run command on the Design tab to execute the search.
- The results appear in Datasheet view. Save the query via the Quick Access Toolbar to preserve your logic for future use.
Mastering the one-table query is your entry point into data analysis. In our next lesson, we will explore how to connect multiple tables to answer even more complex questions.
Challenge!
Practice your architectural skills by designing the following query in our sample database:
- Initiate a new query using the Customers table.
- Include the following fields: First Name, Last Name, City, and Zip Code.
- Implement the following logic:
- In the City field, enter "Durham".
- In the Zip Code field's or: row, enter "27514".
- Run the query to verify that the results include anyone who lives in Durham OR in the 27514 zip code.
- Save your query with the identifier: Customers who live in Durham.