Database Toolbox Previous page   Next Page

Where

After selecting the Fields for a query, from Advanced query options select Where to retrieve only information that meets criteria you specify.

The Where Clauses dialog box appears.

Where Clauses Dialog Box

  1. Select the Fields whose values you want to restrict.
  2. Select a Condition to specify the criteria.
  3. Select Operator to add another condition.
  4. Click Apply to create the clause.
  5. The where clause appears in the Current Clauses area. From Current clauses, you can edit a selected clause or delete it. Click OK to accept all current clauses and close the Where Clauses dialog box. The where clause is then reflected in the SQL statement shown in the Visual Query Builder dialog box.

Examples Using Where Clauses

See help for each element of the dialog box for an example specific to that element.

Example Creating Queries for Results from Multiple Tables

Use Where to create queries whose results include values from multiple tables. For this example, the results include the product description and the sales volumes for each. The table salesVolume has the sales volumes and a stock number field, but not a product description field. Another table, productTable, has the product description and the stock number, but not the sales volumes. Therefore, the query needs to retrieve data from both tables and equate the stock number from productTable with the stock number from the salesVolume table.

  1. In the Visual Query Builder dialog box, select both productTable and salesVolume from Tables. In Fields, select the productTable.productDescription and the salesVolume fields, which are the fields in the query results.
  2. In Advanced query options, click Where. The where clause will equate the productTable.stockNumber with the salesVolume.StockNumber so that the product description can be associated with sales volumes in the results.
  1. The Where Clauses dialog box appears.

  1. In the Where Clauses dialog box, create the association between the fields in the different tables. For example, equate the stock number in productTable to the stock number in the salesVolume table:
    1. Select productTable.stockNumber from Fields.
    2. For Condition, select Relation.
    3. In the drop-down list to the right of Relation, select =.
    4. In the field to the right of the drop-down list, type salesVolume.StockNumber.

    5. Click Apply.
    1. Click OK.
  2. When you click Execute to run the query, the results show sales volumes by product description.

See Also


Previous page  All or Distinct Fields Next page

© 1994-2005 The MathWorks, Inc.