Access Query
As tables grow in size they can have hundreds of thousands of
records, which makes it impossible for the user to pick out specific records from that table.
Queries were designed to combat this problem. With a query you can apply a filter
to the table's data, so that you only get the information that you want.
The tricky part of queries is that you must understand how to construct one before you can
actually use them. This lesson will guide you through the basics of making a couple very simple
Access queries.
Choosing a Table to Query
Before you can create a query you have to navigate to the Query Tab in your
Access database. Select Queries from the Objects Pane.

Although you could use the Wizard, we will guide you through the process of creating an Access query
with the "Design view". We feel this is helpful for beginners, so they don't feel overwhelmed when they
need to do something the Wizard doesn't allow them to.
- Double-click "create Query in Design view"
- Add the table tbl_Sales

- Your Query window should now have the tbl_Sales table added to it

You have just completed the setup process for making a query. Every time you make a query you have to first choose
which table(s) you want to select data from. Currently, our database only has one table, so we don't have a lot of choices here.
Now we can begin to create our custom Access query.
Creating a Custom Query
Bob wants a query that will just return the list of items sold and for how much. He doesn't care
about the sale number or the employee. To make this query we are going to have specify the
fields we want to see and ignore the others.
Access lets you quickly select fields you want to see by a simple drag and drop method. For ever field
that a table has there is an entry in the quick table viewer. Notice that the quick view of tbl_Sales displays
the fields: *, Employee, Product, Price and SaleNumber. Note: The field * is a wildcard, meaning it will select all
the fields if you choose *.
We only want Product and Price, so let's start by dragging Product down from tbl_Sales to the first column. Notice that
when you drop the Product field into the first column it populates two of the fields and checks the "Show" box:

Drag and drop the Price field into the adjoining column and you should have something like:

That's it! You're done! Close the Query window and save your file query as qry_ProdSales.

Running Your First Query!
Well you've finished writing the backend for your query, so let's if it works. Double-click your newly created
query and you should see something like this:

Basic Query Review
When you want to create a query that just uses a select few fields you can simply drag and drop these fields in design view.
The next lesson will go into much more detail on creating custom queries, but remember this, you already have
the knowledge to write queries in Access! Pretty impressive!
Found Something Wrong in this Lesson?Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time! |