Crestline Enterprises: webGED DBQuery
You might want to get a hard-copy of these instructions by using your browser's "PRINT" feature
How to Formulate A Query Using webGED DBQuery


This formal description of the "rules" for formulating queries is intended for those desiring a thorough mastery of all of the advanced features of the language.

Although the rules are actually very intuitive and easy to grasp, an initial reading of them may make the language seem much more complex than it really is. In this regard, if you have not already done so, it is suggested that you first read the Quick-Guide to the language. This will get you acquainted with the basic language features and provide a context for learning the more advanced ones.

Overview

One uses the text-boxes provided on the query form to enter the criteria to be used in the selection of specific records from the datsabase. Each text-box on that form is associated with a specific field (e.g. Child's Surname) of the database. The field associated with each text box is identified in a label to the left of that text-box. You specify the criteria to be used concerning that field by making an entry into it's text-box.

If you enter no criteria into a field's text-box, that field will be ignored in the selection process, i.e. no record will be rejected because of any value that might be present in that field. On the other hand, if you do enter some criteria into a field's text-box, any record where that field does not meet the specified criteria will be rejected. Thus, for a record to be accepted and listed in the response, all the non-blank criteria must be satisfied.

Even though you haven't been exposed to any of the formal rules, you probably should scan through the following set of examples first. They have been chosen to give you an intuitive feel for the language that will make it easier to understand the formal rules. In fact, you may be surprised how much you have absorbed from the examples alone! At worst, you may find an example that directly fits your needs or is close enough to give you the confidence to set off without having to read any further.

Examples that best illustrate some of the more powerful and unique features are identified by a on the left. Also, please pay special attention to the comments in bold since they generally give information that may not be obvious.

Examples Of Criteria On A Single Field

*Text-box EntryExplanation
 IS Samsonchecks for an exact match of the entire field value with the specified criteria value, Samson. Note that all comparison matches, including this one, are by default case-sensitive - although that can be overridden by use of UPPER (see later). Note also that all special command words (IS in this example) must be in all uppercase. The use of a lowercase "is" in this example will cause an error.
 IS "Samson"double-quotes can always be used around any value. Double-quotes are not required in this case, however, since there are no blanks or non-alphabetic characters in the criteria value
 IS "Van Roost"double-quotes are required because of the embedded blank in the criteria value. It would also be required if any non-alphabetic character appeared in the criteria value.
BEGINS Margchecks for any field values beginning with "Marg". Might be used, for example, to match with field values starting with either "Margret" or "Marguerite", etc.
ENDS sonchecks for any field values ending with "son"
CONTAINS Josephchecks for any field values containing the string "Joseph" anywhere. If used in a Given-Names field, for example, this criteria would match field values of "John Joseph", "Joseph", "Henry Joseph Elias", "Joseph George", etc.
Josephany omitted comparison-verb is assumed to be CONTAINS. Thus, this criteria is equivalent to the example immediately above.
UPPER IS LeBlancthe modifier UPPER forces the associated comparison(s) to be made using uppercase versions of both the field value and criteria value. This is most useful when one is unsure how the field value might be capitalized (e.g. Leblanc or LeBlanc).
 IS Samson OR IS Sampsonthe logical-connectors AND and OR can be used to form criteria. Parentheses are not required, except when necessary to remove any ambiguity concerning the grouping of the individual criteria units.
IS (Samson OR Sampson)criteria values governed by identical comparison-verbs may optionally be grouped by use of parentheses. This is equivalent to the example immediately above.
 CONTAINS Joseph AND (CONTAINS Jean OR CONTAINS John)parentheses are required here in order to resolve ambiguity.
Joseph AND (Jean OR John)This is equivalent to the example immediately above. It takes advantage of the feature that all omitted comparison-verbs are taken to be CONTAINS.
 IS NOT Johnthe use of NOT reverses the meaning of the criteria-unit with which it is associated. If the NOT is associated with a unit consisting of a single comparision-verb, as it is here, it may optionally preceed that verb rather than follow it. Thus, "NOT IS John" is completely equivalent to this example.
Some Additional Useful Examples
 Joseph AND NOT (Jean OR John)selects records where the field value contains the string "Joseph", but does not contain either "Jean" or "John". If fully expanded, this would become "CONTAINS Joseph AND NOT (CONTAINS Jean OR CONTAINS John)".
 >=  "1870-01-01" AND
 <  "1870-07-01"
assuming that the criteria is associated with a character-date field with the format YYYY-MM-DD, this selects records with dates in the range from 1 Jan 1870 to before 1 Jul 1870. Note that all comparison-verbs ( >= and <  in this example) must in general be separated by spaces from the other criteria elements. A left parenthesis (or the beginning of the line), however, is also acceptable in place of the left space.

Stating The Criteria

The language to be used in stating criteria is a very simple and intuitive one. Although there are some rules which must be followed, for the most part these are reasonably "natural" and will not require a great deal of efort to learn.

The basic unit used in stating the criteria for an individual field is a comparison, which is simply the combination of a comparison-verb with a value. The legitimate comparison-verbs are: IS , CONTAINS , BEGINS , ENDS, = , > , >= , < , <= . The value can be any string of characters (in some databases, also arithmetic numbers)that might occur in that field in the database.

It is important to note that the value of the associated record field is always the basis of each comparison in the query-criteria. Thus, one would interpret the criteria " IS Samson" in the Child's Surname text-box to mean "[Child's Surname] IS Samson".

The Comparison-verbs

The usage of many of the comparison-verbs is the obvious one, but some explanation may be in order:

IS
This is equivalent to " = ". Checks to see if the associated criteria value exactly matches a record's entire field value. As with all comparision-verbs (exception noted later), this is case sensitive when used with character values.

CONTAINS
Checks to see if the associated criteria-value is found anywhere within a record's field value. This is used only with character values.

BEGINS
Checks to see if the associated criteria-value matches the very beginning of a record's field value. This is used only with character values.

ENDS
Checks to see if the associated criteria-value matches the very end of a record's field value. This is used only with character values.

= , > , >= , < , <=
These check to see is a record's field value would sort in the desired relationship with respect to the associated criteria value. These are most often used with arithmetic values, but are also very useful with character fields, e.g. when the date is carried in the field in character form such as "1850-07-01".
Two rules concerning comparison-verbs are especially important to note:
  1. they must be isolated from the adjacent elements in the criteria statement by at least one space. The only exceptions are that a left parenthesis or the beginning of the statement itself is acceptable on the immediate left of a comparison-verb.

  2. you may omit any occurance of the CONTAINS comparison-verb. It will be automatically inserted in the criteria statement as the default.

Comparison Values

Comparison values may be any string of characters that do not contain any of the following: percent-sign (%), underscore (_), pound-sign (#), double-quote ("), or vertical-bar (|). If the value contains a non-alphanumeric character (e.g. +, -, ?) or a space, it must be enclosed between a pair of double-quotes. It is always acceptable to enclose a value within double-quotes, however, even when this is not necessary.

The Comparison Modifier

At present, the only comparison modifier supported is "UPPER".
UPPER
The association of UPPER with a comparison forces the comparison to be made with both of the operands (i.e. the record field and the criteria value) put into upper case. The reserved word, UPPER, can be placed either immediately before the comparison-verb or between the comparision-verb and its associated criteria-value (e.g. either IS UPPER SAMSON or UPPER IS SAMSON).

The Logical Operators

The logical connectors "AND" and "OR" are used to join simple comparisons into more complex comparisons. The operator "NOT" reverses the result of a comparison.

OR
Joins two adjacent comparisons to form a new comparison such that this new compound comparison is true if and only if any of the component comparisons are true.
AND
Joins two adjacent comparisons to form a new comparison such that this new compound comparison is true if and only if both of the component comparisons are true.
NOT
forms a new comparison that reverses the result of the comparison to its right.
Parentheses should be used to group the component comparisons to avoid ambiguity when multiple logical operators appear in the same criteria-statement. See section below.

Parentheses

Parentheses may always be placed around simple comparisons (e.g. "(IS Samson)"), although the are not necessary in those cases. The may also be placed around compound comparisions that are made up of simple comparisons that are joined by AND and OR conectors. The presence of a set of parentheses around comparisons signals that the entire group of the enclosed comparisons should itself be treated as a simple comparison by the elements outside of the parentheses.

As mentioned above, parentheses are often necessary to avoid ambiguity whenever one or more of the components of a compound comparision is itself a compound comparision (e.g. "(BEGINS John OR BEGINS Jean) AND CONTAINS Pierre"). This also is true when the NOT operator is applied to a compound comparision (e.g. "NOT (IS Jean OR IS John)".

There is another use of parentheses that often may save some verbiage. One may use parentheses to "factor out" an identical comparison verb and/or modifier from a sequence of comparisons. For example, "UPPER IS Samson OR UPPER IS Sampson OR UPPER IS Sancon" could be written as "UPPER IS (Samson OR Sampson OR Sancon)"

It is important to note that the "factoring out" use of parentheses with comparison verbs and modifiers does not apply to NOT, which is neither. NOT always operates on any associated parenthesized expression as though that expression were first evaluted as a single comparision. This will often yield a different result than carrying the NOT into each of the individual comparisons within the parentheses. For example, "NOT (IS John OR IS Jean)" is not logically equivalent to "IS NOT John OR IS NOT Jean".

Merged Multiple Queries

All of the above has been stated in terms of the criteria associated with a single field. As mentioned previously, a complete query consists of the set of individual field criteria, which DBQuery implicitly assumes are to be connected by ANDs. Thus, a record must match the stated criteria for all of its fields for it to be selected.

While this offers considerable flexibility in the formulation of queries, there are many useful queries that cannot be posed within these constraints. Often, multiple queries are required. A good example is the case where one is seeking all records that have "Samson" in either its Father-Surname field or in its Godfather-Surname field. If one simply entered these criteria in the Father-Surname and Godfather-Surname criteria boxes, DBQuery would treat them as being joined by an AND - and not as the OR that is desired.

A way around this would be to run two separate queries and then manually "meld" the two response sets, eliminating whatever duplicates that may occur. DBQuery offers the facility to accomplish this by supporting multiple queries on the same form and automatically merging the response sets.

The Query Separator

It is often useful to run several related queries and then merge the response sets to eliminate duplicate records. To accomplish this, one must enter the criteria associated with each field for all of the queries into that field's criteria-box - separating the individual queries with the "|" character.

|
the Query Separator separates the given field's criteria box into individual distinct query criteria. The criteria associated with the first query must come first, followed by a query separator,then the second query criteria, etc. The absence of criteria associated with a particular query is signaled by the absence of anything following that query's separator. Trailing Separators may be omitted.

The example of the two queries 1) "Father-Surname IS Samson" 2) "Godfather-Surname IS Samson" would be written:

      Father-Surname:   IS Samson |
Godfather-Surname:   | IS Samson

Note that the trailing "|" could have been omitted from the Father-Surname criteria.

Since the Query Separators show that this is two distinct queries, each will be run separately and their response sets then merged - with the duplicates eliminated. The result be be all records with either the Father's or Godfather's Surname as Samson - with those records where both the Father and Godfather's surnames were Samson appearing only once.

A Service of Crestline Enterprises