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 the basic.qry
query that was created and saved as explained in Creating and Running a Query to Import Data. 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.
- From Fields, 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, type
A
in the Command Window. Compare these to the results for all stock numbers, which is a 10-by-4 matrix (see step 7 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 | |
© 1994-2005 The MathWorks, Inc.