SQL Query

This query form offers the next step in complexity and power for extracting data from your WRDB data tables. SQL stands for "Structured Query Language" and is usually pronounced as "sequel". It is a standard language for performing queries that works on multiple computers and database systems. The SQL query form was designed to give you full access to the power of SQL but still help you with SQL’s sometimes difficult language syntax. The SQL query form looks like this:

In this example, the user is requesting all data from the selected browser that meet the criteria: the Station Name starts with "Buford Dam".

Use the SQL Query form by filling in the appropriate fields from left to right. Do this by selecting from the drop-down lists or typing the desired values. As you do so, the SQL statement is interactively built for you in the lower part of the form. The Table Name column is used to specify which table the current line’s criteria refer to. These tables include:

Selected Browser

Stations

Parameter Codes

Compositing Codes

Station Groups

PCode Groups

Tracking Info

After you select one of these, the next column (Field Name) list box automatically fills with that table’s field names (see Database Structure for table names and field names). After selecting one of these, you must apply a comparison operator. The available functions depend on the data type of the field (string, numeric, date-time, or logical). Similarly, comparison operators depend on the field type. Operators and shown below:

 

Field Type

 

String

Numeric

Date-Time

Logical

Operators:

=

Like

<>

>

>=

<

<=

Between

Is Null

Is NotNull

=

<>

Between

>

>=

<

<=

=

<>

Between

>

>=

<

<=

=

<>

The "Like" operator may be very useful for advanced queries because it allows you to use wildcard characters to match strings. Allowable wildcard characters are:

Match..

DOS-style

SQL-style

..any single character

?

_

..all remaining characters

*

%

Wildcard characters you enter are always converted to SQL-style when WRDB forms the SQL statement. For example, to match all Station IDs for which the third character of the ID is an "X", use the "Like" operator and type the Criteria as "??X*".

The "Add More Criteria" button is used to add additional criteria. When selected, you must choose how to combine the new criterion with prior criteria. You can select from "And", "Or", "And Not", and "Or Not". In SQL all "and" operations are carried out before all "or" operations. For example, four conditions linked as "A and B or C and D" are treated like "(A and B) or (C and D). If you desire some other order of logical operations, you need to manually add parenthesis in the SQL statement after all criteria have been specified above (for example "A and (B or C) and D").

If you check the box titled "Display available values in condition drop-down", each time you change the field name, WRDB runs a query to determine the unique values for that field in the selected data table. For example, if you select the field "Station_Name" for the Stations Support table, WRDB fills the Criteria drop-down list with unique station names found in that table. Take care when you select this checkbox; the queries can take a long time for large data tables.

While this discussion SQL operators may seem complex as you read it, it is fairly intuitive to use. As you select functions, operators and criteria from the drop-down lists, you will see the SQL statement instantly modified. Not only can you perform complex queries very rapidly with the "point-and-shoot" interface, you’ll be learning the SQL language. At some point you may wish to just type your SQL query and bypass the interactive interface entirely. Please note that all query results are forced to create a temporary result "view" so some types of manual SQL queries will be inappropriate.

See also SQL Queries.