Database Toolbox Previous page   Next Page

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:

  1. Load basic.qry. For instructions, see Using a Saved Query.
  2. Set Preferences; for this example, set Data return format to cellarray and Read NULL numbers as to NaN.
  3. In Advanced query options, click Where.
  1. The Where Clauses dialog box appears.

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

    4. Click Apply.
  3. 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.
    1. Select StockNumber > 400000 from Current clauses.
    2. Click Edit (or double-click the StockNumber entry in Current clauses).
    1. For Operator, select AND.
    2. Click Apply.
  4. Add the new condition. For example, specify that StockNumber must also be less than 500000.
    1. From Fields, select StockNumber.
    2. Select Relation from Condition.
    3. From the drop-down list to the right of Relation, select <.
    4. In the field to the right of the drop-down list, type 500000.
    5. Click Apply.
  5. Click OK.
  1. 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.

  1. Assign a MATLAB workspace variable; for example, A.
  2. Click Execute.
  1. The results are a 6-by-4 matrix.

  1. 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).

  2. Select Save from the Query menu and name this query basic_where.qry for use with subsequent examples.

Previous page  Retrieving Unique Occurrences Grouping Criteria Next page

© 1994-2005 The MathWorks, Inc.