ACC: How to Create and Use SubqueriesLast reviewed: May 14, 1997Article ID: Q114678 |
The information in this article applies to:
SUMMARYModerate: Requires basic macro, coding, and interoperability skills. Microsoft Access supports the use of subqueries. A subquery is a select query inside another select or action query that acts as a criterion for a field. A subquery can refer to a table that is part of the current query, or to a table that is not part of the current query. Union and crosstab queries are not supported as subqueries.
MORE INFORMATIONTo create a subquery, enter a valid SQL SELECT statement in the Criteria cell of the field whose value will be compared with the value selected in the subquery. The field that the criterion is specified for and the field that is being selected in the subquery must be of the same data type. You can also have a subquery in the Field row of the query grid, although it is not recommended. A correlated subquery is one in which a column from a table specified in the FROM clause of the main query is used in the WHERE clause of the subquery, as demonstrated in the following example:
SELECT * FROM Table1 WHERE FirstName IN (SELECT FirstName FROM Table2 WHERE Table2.LastName=Table1.LastName);Another way to tell if a subquery is a correlated subquery is that if the subquery statement couldn't be used by itself as a separate query. In the example above it wouldn't know what Table1.LastName was. The following example demonstrates how to create a subquery:
REFERENCESFor more information about creating subqueries, search the Help Index for "Subqueries," or ask the Microsoft Access 97 Office Assistant.
|
Additional query words: sub-select
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |