using special select queries

64
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 Microsoft Access 2000 Class #5

Upload: idana

Post on 04-Jan-2016

76 views

Category:

Documents


0 download

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

TRANSCRIPT

Page 1: Using Special Select Queries

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

Page 2: Using Special Select Queries

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!

Page 3: Using Special Select Queries

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

Page 4: Using Special Select Queries

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

Page 5: Using Special Select Queries

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

The Criteria RowThe Criteria Row

Page 6: Using Special Select Queries

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

The Criteria RowThe Criteria Row

Page 7: Using Special Select Queries

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 (#).

Page 8: Using Special Select Queries

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

Page 9: Using Special Select Queries

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.

Page 10: Using Special Select Queries

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.

Page 11: Using Special Select Queries

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.

Page 12: Using Special Select Queries

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.

Page 13: Using Special Select Queries

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

Page 14: Using Special Select Queries

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.

Page 15: Using Special Select Queries

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

Page 16: Using Special Select Queries

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

Page 17: Using Special Select Queries

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.

Page 18: Using Special Select Queries

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

Page 19: Using Special Select Queries

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.

Page 20: Using Special Select Queries

To answer Barbara’s question we would have to enter

Page 21: Using Special Select Queries

This criteria would return something like

Page 22: Using Special Select Queries

You have the option of entering this criteria in two ways

Page 23: Using Special Select Queries

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.

Page 24: Using Special Select Queries

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.

Page 25: Using Special Select Queries

Hmm??

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

Page 26: Using Special Select Queries

What if ?

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

Page 27: Using Special Select 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.

Page 28: Using Special Select 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!

Page 29: Using Special Select Queries

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

Page 30: Using Special Select Queries

The solution is a parameter query!

Page 31: Using Special Select Queries

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.

Page 32: Using Special Select Queries

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.

Page 33: Using Special Select Queries

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.

Page 34: Using Special Select Queries

Is the Sunin the Sky?

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

The solution is “CrossTab “CrossTab

Queries”!Queries”!

Page 35: Using Special Select 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,

Page 36: Using Special Select Queries

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

Page 37: Using Special Select Queries

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

Page 38: Using Special Select Queries

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

Page 39: Using Special Select Queries

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

Find DuplicatesFind UnmatchedTop Values

Page 40: Using Special Select Queries

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

Page 41: Using Special Select Queries

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

Page 42: Using Special Select Queries

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

Page 43: Using Special Select Queries

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

Page 44: Using Special Select Queries

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

Page 45: Using Special Select Queries

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.

Page 46: Using Special Select Queries

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

Page 47: Using Special Select Queries

The last select query that we will explore is called a

Top Values Query

Page 48: Using Special Select Queries

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.

Page 49: Using Special Select Queries

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.)

Page 50: Using Special Select Queries

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

Page 51: Using Special Select Queries

Page AC 5.23

Quick Check Review

Page 52: Using Special Select Queries

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.

Page 53: Using Special Select Queries

Quick Check Quick Check Review Session Review Session

5.15.1

1) What is a Lookup Wizard field?

Page 54: Using Special Select Queries

Quick Check Quick Check Review Session Review Session

5.15.12) What is a subdatasheet?

Page 55: Using Special Select Queries

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.

Page 56: Using Special Select Queries

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?

Page 57: Using Special Select Queries

Quick Check Review Quick Check Review Session 5.1Session 5.1

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

Page 58: Using Special Select Queries

Quick Check Review Quick Check Review Session 5.1Session 5.1

6) When do you use the In Comparison operator?

Page 59: Using Special Select Queries

Quick Check Review Quick Check Review Session 5.1Session 5.1

7) How Do you negate a selection criterion?

Page 60: Using Special Select Queries

Quick Check Review Quick Check Review Session 5.1Session 5.1

8) When do you use a parameter query?

Page 61: Using Special Select Queries

Here we goagain !

Page 62: Using Special Select Queries

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!

Page 63: Using Special Select Queries

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

Page 64: Using Special Select Queries

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

Tutorial #5 Level 2 Disk1