Database Toolbox | ![]() ![]() |
Creating Subqueries for Values from Multiple Tables
Use the Where feature in Advanced query options to specify a subquery, which further limits a query by using values found in other tables. This example uses basic.qry
(see Building, Running, and Saving a Query).
This example retrieves sales volumes for the product whose description is Building Blocks. The table used for basic.qry
, salesVolume
, has sales volumes and a stock number field, but not a product description field. Another table, productTable
, has the product description and stock number, but not the sales volumes. Therefore, the query needs to look at productTable
to get the stock number for the product whose description is Building Blocks, and then has to look at the salesVolume
table to get the sales volume values for that stock number.
basic.qry
. For instructions, see Using a Saved Query.This creates a query that retrieves the values for January, February, and March sales for all stock numbers.
productTable
, which contains the association between the stock number and the product description.stockNumber
.productDescription
from Fields.
=
.
'Building Blocks'
(include the single quotation marks).
The clause appears in the Current subquery WHERE clauses area and updates the SQL subquery statement.
This closes the WHERE Clauses dialog box and updates the SQL statement in the Visual Query Builder dialog box.
C
.C
at the prompt in the MATLAB Command Window to see the results.dbtoolboxdemo
as the Data source.
productTable
from Tables.
stockNumber
and productDescription
from Fields.
P
.
P
at the prompt in the Command Window to view the results.The results show that item 400345 has the product description 'Building Blocks'
. Creating Queries for Results from Multiple Tables creates a query that includes the product description in the results.
![]() | Presenting Results in Specified Order | Creating Queries for Results from Multiple Tables | ![]() |