OurTown2000 Query Handbook - To Modify a Query

<-Back (To Modify a Query-The Query Overview Dialog) Table of Contents Next (To Modify a Query-Selecting Fields to Show in Query)->

The Filter Building Dialog

 

Every query is an attempt to extract a subset of information contained within your database system. The Filter Building dialog is where you specify a set of conditions to determine the subset you are seeking. This set of conditions is your filter.

 

You can access this dialog from the Query List Manager by pressing the Add or Edit button.

What is a Condition?

A condition is a “phrase” that defines the set of data you are seeking.  For example, "Amount is greater than $1000".   A condition consists of:

1.    a field name   (e.g., "Amount")

2.    a relational operator   (e.g., "is greater than")

3.    a comparison value   (e.g., "$1000").

·      Each condition you add can narrow the results of the query.   That is, fewer records may be included in the query results.

·      Each condition you delete can expand the results of the query.  That is, more records may be included in the results.

·      Each query can contain up to 10 conditions.

These are the actions you can perform in the Filter Building dialog:

Button

Action

Description

 

Add a new condition.

You will be prompted to select a field, pick a relational operator and type in a comparison value.

Edit an existing condition.

Change a condition's field, operator, comparison value (or any combination of these).  These terms are explained below.

Switch a condition's connector between an AND and an OR.

If two conditions are connected by an "AND", both must be true (e.g., car color is blue and car make is Ford).  If, however, two conditions are connected by an "OR", either can be true (e.g., car is either blue or a Ford). 

Move the position of a condition within the list of conditions.

If you are mixing both "AND" and "OR" connectors or are using parentheses, the order of the conditions can determine which records are included in the query results.

Place or remove parentheses around two or more  conditions.

Complex queries may have several AND and OR connectors. The placement and organization of these connectors can make a difference in the results.

(See Making the Right Connections. in this section)

Delete a condition from the list.

Deleting a condition will generally widen the results of the query.

Exit this dialog without saving.

This will undo any changes you made while you were in this Filter Building Dialog.

Save and exit.

This will save your work and return you to the Query List Manager.

Display help.

This will display information you may find helpful.

AND / OR Connectors

A filter consists of one or more conditions.  Conditions can be strung together with AND and OR connectors. How you connect the various conditions makes a big difference in the results:

 

Filter

Results

 

AND

 

Customer ZIP exactly equals “11366”

AND

Product exactly equals “AX5000”

 

Every record included in the query results must meet both conditions. The customer ZIP must be 11366 and the product purchased must be AX5000.

 

RULE: The conditions on both sides of the AND connector must be true.

OR

Customer ZIP exactly equals “11366”

OR

Product exactly equals “AX5000”

Records included in the query results must meet either condition.   The results will show all customers in ZIP code 11366 and all customers who purchased product number AX5000.

RULE: Only one side of the OR condition must be true.

 

OT2 Query Maker makes one pass across your data, examining each record for all conditions and then either accepts or rejects the record for inclusion in your output.

Making the Right Connections

 If you create queries with many AND and OR conditions, be sure to use brackets (parentheses) to ensure you get the results you are expecting.  Parentheses dictate how the query is interpreted.  The query is evaluated first in the innermost parentheses.  Without parentheses, the query conditions are evaluated from left to right.

           

To Get This

Use This Query

Result

 

All orders for product AX5000 as well as customers in ZIP code 11366 who have not returned merchandise.

 

Product Exactly Matches "AX5000"

 OR     

(ZIP Code Exactly Matches "11366"

AND Returned is False)

Orders for product AX5000 as well as
customers from ZIP code 111366.

In both cases, we want to show records for only kept merchandise. So the Returned is False condition appears as a separate factor on the other side of the AND connector.

(Product Exactly Matches AX5000"

OR      

ZIP Code Exactly Matches "11366")

AND   

Returned is False

 

For another example that illustrates the importance of using parentheses with AND/OR connectors, see Appendix A.


<-Back (To Modify a Query-The Query Overview Dialog) Table of Contents Next (To Modify a Query-Selecting Fields to Show in Query)->

OurTown2000 Query Handbook - To Modify a Query