Office 2007 - Access

Lesson 19: Queries

19/72 Lessons 

What is a “Query”?

You use “Queries” to answer a question about the data you have stored in the database tables.
You can use the results from the “Query” and further analyze them.

For example, reports are often based on “Query” results, on which we perform additional mathematical and statistical calculations.

“Queries” are also an excellent way to display information from linked tables as a single result table.

The power and flexibility of a “Query” is actually the only reason why we use database programs like “Access”.

They can merge records from different tables with a miraculous speed and also perform calculations.

First we take a look at the “Query Wizard” but, do not depend too much on this tool because in practice you will more than likely have to compose “Queries” that are more complex than what a wizard does.

“Query Wizard”

A “Query” can be made in a number of ways.

A first way is by using the “Query Wizard “.

Select the “Create” tab in the “Ribbon” and click the “Query Wizard”.

This opens the “New Query” dialog.

On the left of this dialog box, we find a small description of the type of wizard we have selected on the right side of the dialog.

We have a choice of four types of “Queries”:
The first, “Simple Query”, indicates the option to create a  “Query”, from the selected fields of one or more tables.

The second option, “Crosstab Query” allows us to create a crosstab “Query” of the selected fields in a compact form and display it like an “Excel” worksheet.

The third option, “Find Duplicates Query” is a “Query” that searches records with duplicate field values in a single table.

The last option, “Find Unmatched Query” creates a “Query” that finds records that have no related records in another table.

In this example I choose the first option “Simple Query” and click the OK button.

This opens the “Simple Query Wizard”  window.

In the top box, choose a table for which you want to make a “Query”.

Just click the downward pointing arrow and choose a table or “Query”.

Since we have no “Queries” at this time, there will be only tables in this list.

In the “Available fields” we see all the fields from the table you just selected.

Select the fields you want in your “Query” and click the button with the ‘>’ sign.

If you wish to add all the fields from this table into your “Query”, click the button with the ‘>>’ sign.

To remove fields from the “Query”, select the field in the right side of the dialog box and click the button with the ‘<‘ sign

To delete all columns, click the button with the ‘<<‘ button.

In this example I want to use fields from two tables, namely the “Album” table and the “Song” table.

In the “Album” table, I want the fields “Type”, “Album Title” and “Location”.

In the “Song” table, I want the fields “SongTitle”, “Genre” and “Date”.

So I select the “Album” table first in the “Tables / Queries” and place fields from this table under the “Available fields” box to the “Selected Fields” box.

Then I choose the “Song” table in the “Tables / Queries” and place the other fields I mentioned above from  the “Available Fields” box to the “Selected Fields” box.

Click the “Next” button in the dialog.

In the second window, we must decide whether we want detail or summary “Query”.

I choose the first option “Detail ( shows every field of every record).”
The second option, “Summary”, is available only when you have a numeric field in a table (I will give an example for this in the next lesson).

Click the “Next” button.

In the third window of the “Query”, we give it an appropriate name in the top box.

Select the checkbox “Open the query to view information.”
About the “Modify the query design” option, I will discuss in the next lesson.

Click the “Finish” button.
When we open, we see that all fields that we have just selected from the two tables, displayed in this “Query”.

Awesome!
You've completed Lesson 19
START NEXT LESSON