Database Toolbox |
 |
Retrieving Information That Meets Specified Criteria
Use the Where field in Advanced query options to retrieve only the information that meets the criteria you specify. This example uses basic.qry
, that was created and saved as explained in Creating, Running, and Saving a Query. It limits the results to those stock numbers greater than 400000 and less than 500000:
- Load
basic.qry
. For instructions, see Using a Saved Query.
- Set Preferences; for this example, set Data return format to
cellarray
and Read NULL numbers as to NaN
.
- In Advanced query options, click Where.
- The Where Clauses dialog box appears.

- Select the Fields whose values you want to restrict. For example, select
StockNumber
.
- Use Condition to specify the criteria. For example, specify that the
StockNumber
be greater than 400000
.
- Select Relation.
- From the drop-down list to the right of Relation, select
>
.
- In the field to the right of the drop-down list, type
400000
.

- Click Apply.
- You can add another condition. First you edit the current clause to add the
AND
operator to it, and then you provide the new condition.
- Select
StockNumber > 400000
from Current clauses.
- Click Edit (or double-click the
StockNumber
entry in Current clauses).
- For Operator, select AND.
- Click Apply.
- Add the new condition. For example, specify that
StockNumber
must also be less than 500000
.
- From Fields, select
StockNumber
.
- Select Relation from Condition.
- From the drop-down list to the right of Relation, select
<
.
- In the field to the right of the drop-down list, type
500000
.
- Click Apply.
- Click OK.
- The Where Clauses dialog box closes. The Where field and the SQL statement in the Visual Query Builder dialog box reflect the where clause you specified.
- Assign a MATLAB workspace variable; for example,
A
.
- Click Execute.
- The results are a 6-by-4 matrix.
- To view the results, double click the
A
in the Data area of the VQB and they appear in the Command Window. Compare these to the results for all stock numbers, which is a 10-by-4 matrix (see step 6 in Building and Executing a Query).

- Select Save from the Query menu and name this query
basic_where.qry
for use with subsequent examples.
| Retrieving Unique Occurrences | | Grouping Criteria |  |