A:\minispir.GIF
A:\minispir.GIF
Querying a Database
SESSION3.1
This section covers using the query window in design viewto create a query and sorting & filtering data while in adatasheet view.
Microsoft Access 2000 Class #4
The Major Steps of a MicroSoftAccess Database
Tables
Queries
Forms
Macros
Reports
Modules
On our road map, we are here!
On our road map, we are here!
A query is a questionyou ask about datastored in a database.
For example, youmight create a queryto find records in theCustomer table foronly those customersin a specific state.
When you create a query, you tellAccess which fields you need andwhat criteria Access should use toselect the records.
Customer ID
Name
Address
City State  Zip
All Customers in Ohio
Access provides powerful querycapabilities that allow you to:
  Display selected fields and records from a table.
  Sort records
  Perform calculations
  Generate data for forms, reports and other queries
  Update, (modify) data in tables in a database
  Find and display data from two or more tables
Most questions about data aregeneralized queries in which youspecify the fields and records youwant Access to select.
These common requests forinformation, such as “Whichcustomers have unpaid bills?”
or  “Which type of coffee
sells best in Ohio?”
                  are called
                      select queries.
The answer to a select query is returned inthe form of a datasheet.
More specialized, technical queries, such asfinding duplicate records in a table, are bestformulated through a Query Wizard.
Queries
Cool
A Query Wizard promptsyou for information througha set of questions and thencreates the appropriatequery based on youranswers.
For common,informational queries, itis easier for you to designyour own query ratherthan use a Query Wizard.
The Query Window
You use the Query window in Designview to create a query.  In Design viewyou specify the data you want to viewby constructing a query by example.Using query by example  (QBE), yougive Access an example of theinformation you are requesting.  Accessthen retrieves the information thatprecisely matches your example.
In Design view, the Select Query windowcontains the standard title bar, toolbar,and status bar.
On the tool bar, the Query Type button shows aselect query; the icon on this button changesaccording to the type of query you are creating.
The title bar on the Select Query window displaysthe query type, Select Query, and the defaultquery name, Query1.
Field List
Design Grid
Tool Bar
View Button for Datasheet View
This button will toggle viewsbetween the datasheet viewand the design view
The pull down arrow tothe right of the buttonwill show the options.
An alternative method oftoggling between the designview and data sheet view is touse View on the Menu Bar.
Query Type Button
This button will toggle or change the type ofquery that we want.
The pull down arrow to the right of the buttonwill show the options.
We will be using the SelectQuery Type for this class.
In the design grid , you include the fieldsand record selection criteria for theinformation you want to see.  Each columnin the design grid contains specificationsabout a field you will use in the query.  Youcan choose a single field for your query bydragging its name from the field list to thedesign grid in the lower portion of thewindow.  Alternatively, you can doubleclick a field name to place it in the nextavailable column in the design grid.
Field List
Design Grid
Field Name  Row in Design Grid
If the query you are creatingincludes all the fields from thespecified table, you could useone of the following threemethods to transfer all thefields from the filed list to thedesign grid.
Field List
Design Grid
Click and drag each fieldindividually from the field list tothe design grid.  Use this methodif you want the fields in yourquery to appear in an order thatis different from the order in thefield list.
Field List
Design Grid
Double-click the asterisk in thefield list.  Access places the tablename followed by a period and anasterisk (as in “Costomer.*”) inthe design grid.
Field List
Design Grid
This signifies that the order of thefields will be the same in thequery as it is in the field list.  Usethis method if the query does notneed to be sorted or to haveconditions for the records youwant to select.
Field List
Design Grid
The  advantage of this method isthat you do not need to changethe query if you add or deletefields from the underlying tablestructure.  They will appearautomatically in the query.
Field List
Design Grid
With the third method, Double-click the field list title bar tohighlight all the fields, and thenclick, hold and drag one of thehighlighted fields to the designgrid.
Field List
Design Grid
Access places each field in aseparate column and arrangesthe fields in the order in whichthey appear in the field list.  Usethis method rather than theprevious one if your query needsto be sorted or to include recordselection criteria.
Sorting Data in a Table Query or Form
The Sort Ascending and
Sort Descending buttons
 on the toolbar allow you
 to sort records immediately, based on theselected field. First you select the columnon which you want to base the sort, andthen click the appropriate sort button onthe toolbar to rearrange the records ineither ascending or descending order.
We will see other sorting methods later.
Filtering Data in a Table Query or Form
A filter is a set of
restrictions you place on
the records in an open
datasheet or
form to
temporarily
isolate a
subset of the
records.
Filtering Data in a Table Query or Form
A filter lets you view
different subsets of
displayed records so
you can focus
on only the
data you need.
Filtering Data
Unless you save a query orform with a filter applied,
an applied filter
is not available
the next time you
run the query or
open the form.
Filtering Data
The simplest technique for filtering records isfilter by selection.
Filter By Selection lets you select all or part of afield value in a datasheet or form, and thendisplay only those records that contain theselected value in the field.
Filtering Data
Another technique for filtering records is to useFilter By Form.
Filter by Form changes your datasheet to display emptyfields.  Then you can select a value from the list arrowthat appears when you click any blank field to apply afilter that selects only those records containing that value.
right clickYou can also right click in a field to activate apop-up menu that will give you filtering andsorting options.
FilterExcluding SelectionWith this method, you also have the FilterExcluding Selection, which is the opposite ofFilter by Selection.
Filter For optionYou also have the Filter For option, whichallows you to type in the criteria that you arelooking for.
Page AC 3.19
Quick Check Review
A:\minispir.GIF
A:\minispir.GIF
Quick CheckReview
Let’s take a few
moments to break up
into discussion groups.
Each group will discuss
the quick check questions on pageAC 3.19 in your books.   We will thenreview the answers at the end of thediscussion.
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
1)  What is a select query?
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
2)  Describe the field list and thedesign grid in the Query window inDesign view.
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
3)  How are a table datasheet and aquery datasheet similar?  How arethey different?
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
4)  The ______ is the “one” table ina one-to-many relationship, and the_______ is the “Many” table in therelationship.
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
5)  _______ is a set of rules thatAccess enforces to maintainconsistency between related tableswhen you update data in adatabase.
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
6)  For a date / time field, what isascending sort order?
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
7)  When must you define multiple sortkeys in Design view instead of in the querydatasheet?
A:\minispir.GIF
A:\minispir.GIF
Quick Check ReviewSession 3.1
8)  A(n) ________ is a set ofrestrictions you place on therecords in an open datasheet orform to isolate a subset of recordstemporarily.
You have been requested to helpthe people at Valle Coffee withcreating queries that willanswer their questions.
Your assignment today is to do the classexercises starting on
Page AC 3.01 through page AC 3.19
Disk to use for this Class:
 
      Tutorial  3
                                       Level 1  Disk 1
                                       Restaurant .mdb
 
Class # 3Tutorials
Tutorial 3 beginning on Page AC 3.01 andworking through Page AC 3.19