Using Special Select Queries

Preview:

DESCRIPTION

SESSION 5.1. In this session we will be exploring Pattern Match Queries List-Of-Values Queries, Non-Matching Values in Queries Both the “And” and the “OR” Operators Parameter Queries (or “Prompt Queries”) CrossTab Queries TopValue Queries. Using Special Select Queries. - PowerPoint PPT Presentation

Citation preview

SESSION 5.1

In this session we will be exploring Pattern Match QueriesList-Of-Values Queries, Non-Matching Values in QueriesBoth the “And” and the “OR” Operators Parameter Queries (or “Prompt Queries”) CrossTab Queries TopValue Queries

Microsoft Access 2000 Class #5

TheThe MajorMajor Steps of a Steps of a MicroSoft Access MicroSoft Access

DatabaseDatabase TablesTables QueriesQueries FormsForms MacrosMacros ReportsReports ModulesModules

On our road map, we are here!On our road map, we are here!

Remember, a query is a question you ask about data stored in a database.

Pattern Match Queries, List-Of-Values Queries, Non-Matching Values in Queries, Both the “And” and the “OR” Operators and Parameter Queries (or “Prompt Queries”) are all simply normal select queries that use criteria.

The Criteria RowThe Criteria Row

Last session we looked at defining record selection by using criteria and creating calculated fields in Select queries.

The Criteria RowThe Criteria Row

In this session we will look at specific criteria in Select queries.

The Criteria RowThe Criteria Row

Let’s take a quick look at the “Like”, “In”, “Not”, & the “And / Or” comparison operators that we will be using in our class exercise for this session.

The “Like” comparison operator (used in pattern matches) selects records by matching field values to a specific pattern that includes one or more wildcard characters - asterisk (*), question mark (?), and the number symbol (#).

To show only those records with an area code of 313 you would enter this in the Phone Criteria Row

In the previous example we used parentheses ( ) in our criteria expression.. If we had not needed the parentheses we could have simply typed 313* and Access would have inserted the word Like and the quotes for us.

The asterisk represents any string of characters, the question mark represents any single character, and the number symbol represents any single digit.

Using a pattern match is similar to using an exact match, except that a pattern match includes wildcard characters.

A list-of-values match selects records whose value for the selected field matches one of two or more simple condition values. You could accomplish this by including several “Or” conditions in the design grid, but Access also provides the “In” comparison operator that works as a shorthand.

The “In” comparison operator allows you to define a condition with two or more values.

If a record’s field value matches at least one value from the list of values, Access selects that record for inclusion in the query results.

To show all records that contain CustomerNum 123, 135 and 202 you would enter this in the CustomerNum Criteria row

A non-matching value selects records whose value for the selected field does not match the simple condition value.

You create the selection criterion using the “Not” logical operator.

To omit all states that begin with the letter M you would enter this in the State Criteria row

You could also type just Not M* and Access would insert the Like and Quotes for you.

Let’s talk about something called compound conditions for a moment.

Barbara just came in and asked to see a list of all customers in Ohio and Michigan.

Notice the word “and” in Barbara’s request.

What would happen if we typed “OH” And “MI” in the State Field’s Criteria Row?

The result would look something like this, not finding anything. That’s because we have asked Access to show us all records that contain both MI and OH in the same field.

To answer Barbara’s question we would have to enter

This criteria would return something like

You have the option of entering this criteria in two ways

Using the second method as shown below

Would return only records in Ohio that contain “756” in the Phone field and every record in Michigan.

Using the second method as shown below

Would return only records in Ohio that contain “756” in the Phone field and only records in Michigan that contain “756” in the Phone field.

Hmm??

Lately it seems as though the questions are getting more and more intense!

What if ?

Barbara especially is beginning to realize that many unsolved mysteries can be solved with this program by using queries.

This has been causing Barbara’s Staff aconsiderable amountof concern.

Two things have beenhappening. First, more and more time has been spent creating queries.

Secondly, The number of queries is growingand it’s becomingmore and more difficult to keeptrack of whichquery is which.

There is an answer to this dilemma!

The wizards at Microsoft have come up with a very simple solution!

The solution is a parameter query!

A parameterquery is aquery thatprompts youfor criteriawhen the query is viewed or run. When Access runs the query, it will display a dialog box and prompt you to enter the criteria desired.

To create a parameter query, simply enter the text that you want as your prompt in square brackets in the criteria row for the field that you want to set the criteria for.

Can I get summaries ?

Leonard is interested . in how much business . Valle Coffee is . doing in each . state! He wants . to know the . total sales by . state and by . month.

Is the Sunin the Sky?

The answer is “YES!”.“YES!”.

The solution is “CrossTab “CrossTab

Queries”!Queries”!

and displays the results in a spreadsheet like format.

A Crosstab query performs aggregate (total) function

calculations on the values of one database field,

through the steps for creating crosstab queries.

The quickest way to create a crosstab query is to use the Crosstab Query Wizard, which guides you

A Crosstab query can also display one additional aggregate function value that summarizes each row’s set of values.

The crosstab query datasheet below shows the total sales for each month by state and shows a row total.

There are 3 other types of select queries that we need to take a quick look at.

Find DuplicatesFind UnmatchedTop Values

Finding duplicate records in very large databases can be a very distasteful and tedious task

A find duplicates query is a select query that locates duplicate records in a table or query.

You can create this type of query using the Find Duplicates Wizard!

Finding unmatched records in very large databases can also be a very tedious task

A find unmatched query is a select query that locates unmatched records in a related table.

For example, if you can not establish referential integrity betweenthe Customer Tableand Order Table,you might have acustomer # in the ordertable that does not exist inthe customer table.

You can create this type of query using the Find Unmatched Query Wizard!

The last select query that we will explore is called a

Top Values Query

Whenever you have a query that displays a large group of records, you can limit the number to a more manageable size by showing just the first 10 records for example.

The Top Values property for a query lets you limit the number of records in the query results. For the Top Values property, you enter either an integer (such as 10, to show the first 10 records) or a percent (such as 50%, to show the first half.)

The Top Values Query Button can be found on the Query Design Window’s Tool Bar as shown below:

Page AC 5.23

Quick Check Review

Quick Check Quick Check ReviewReview

Let’s take a fewmoments to break upinto discussion groups.Each group will discussthe quick check questions on page AC 5.23 in your books. We will then review the answers at the end of the discussion.

Quick Check Quick Check Review Session Review Session

5.15.1

1) What is a Lookup Wizard field?

Quick Check Quick Check Review Session Review Session

5.15.12) What is a subdatasheet?

Quick Check Quick Check Review Session Review Session

5.15.13) A(n) ___________ is a predefined format you use to enter data in a field.

Quick Check Review Quick Check Review Session 5.1Session 5.1

4) Which comparison operator is used to select records based on a specific pattern?

Quick Check Review Quick Check Review Session 5.1Session 5.1

5) What is the purpose of the asterisk (*) in a pattern match query?

Quick Check Review Quick Check Review Session 5.1Session 5.1

6) When do you use the In Comparison operator?

Quick Check Review Quick Check Review Session 5.1Session 5.1

7) How Do you negate a selection criterion?

Quick Check Review Quick Check Review Session 5.1Session 5.1

8) When do you use a parameter query?

Here we goagain !

The staff at Valle Coffee have just finished their weekly meeting and as you can expect, there are more

questions than ever to be answered!

Your task today is to complete the exercises in Tutorial #5 Page AC 5.14 through Page AC 5.23

Please make a note that the disks to use for today’s class are:

Tutorial #5 Level 2 Disk1

Recommended