Microsoft Access 2010 Bible

(Rick Simeone) #1

Part I: Access Building Blocks


130


the query’s data is used. In many cases it makes more sense to include logic such as transforma-
tions, combinations, and sorting in a query, instead of performing these actions at the form or
report level.

Introducing Queries


A database’s primary purpose is to store and extract information. Information can be obtained from
a database immediately after the data is added, or days, weeks, or even years later. Of course,
retrieving information from database tables requires knowledge of how the database is designed.

For example, consider printed reports kept in a traditional filing cabinet, arranged by date and by a
sequence number that indicates when the report was produced. To find a specific report, you must
know its year and sequence number. In a good filing system, you might have a cross-reference
book to help you find a specific report. This book might have all reports categorized alphabetically
by type of report and, perhaps, by date. Such a book can be helpful, but if you know only the
report’s topic and approximate date, you still have to search through all the sections of the book to
find out where to get the report.

Unlike manual filing systems, databases like Microsoft Access quickly and easily retrieve informa-
tion to meet virtually any criteria you specify.

This is the real power of a database — the capacity to examine the data in more ways than you can
imagine. Queries, by definition, ask questions about the data stored in the database. Most queries
are used to drive forms, reports, and graphical representations of the data contained in a database.

What queries are
Let’s start with the basics. The word query comes from the Latin word quaerere, which means “to
ask or inquire.” Over the years, the word query has become synonymous with quiz, challenge,
inquire, or question.

A Microsoft Access query is a question that you ask about the information stored in Access tables.
You build queries with the Access query tools, and then save it as a new object in the Access data-
base. Your query can be a simple question about data in a single table, or it can be a more complex
question about information stored in several tables. After you submit the question, Microsoft
Access returns only the information you requested.

Using queries this way, you might ask the Collectible Mini Cars database to show you only trucks
that were sold in the year 2012. To see the types of trucks sold for the year 2012, you need infor-
mation from three tables: tblSales, tblSalesLineItems, and tblProducts. Figure 4.1
shows just such a query in the Access query designer. Although it might look complex, it’s actually
very simple and easy to understand.
Free download pdf