When filtering the fields of a query with the filter format, you are also enabled to use sub-queries to narrow down the result according to your requirements. The following are syntaxes that can be used in sub-queries.
Quantified predicate
A quantified predicate compares a value with a set of values.
expression----+- = --+- SOME --+-- ( subselect )
+- <> -+ ANY ---+
+- ! = --+ ALL ----+
+- < --+
+- > --+
+- <= --+
+- ! > --+
+- >= --+
+- ! < --+
The subselect must specify a single result column and can return any number of values, whether they are null or not.
SELECT qty FROM sales WHERE qty>= ALL (SELECT qty FROM sales)
SELECT BUYERID, ITEM FROM ANTIQUES WHERE PRICE != ANY (SELECT PRICE FROM ANTIQUES);EXISTS predicate
The EXISTS predicate tests for the existence of certain rows.
- [ NOT ] EXISTS--(subselect)
The subselect may specify any number of columns and,
SELECT DISTINCT pub_name FROM publishers WHERE EXISTS (SELECT * FROM titles WHERE pub_id = publishers.pub_id AND type = 'business')IN predicate
The IN predicate compares a value with a set of values.
expression----+-- [NOT] IN --+-- ( subselect )
In the subselect form, the subselect must identify a single result column and may return any number of values, whether null or not null.
SELECT distinct pub_name FROM publishers WHERE pub_id IN (SELECT pub_id FROM titles WHERE type = 'business')The following example explains how to apply a sub-query when filtering a field:
beside the field text box. In the Expressions dialog, select the column Customers_Customer ID, then close the dialog.
beside the value text box. In the Expressions dialog, click the Subquery tab. Select an existing query in the catalog to be the sub-query. If you want to edit the selected query, click the Edit Subquery button. To create a new sub-query, click the New Subquery button.
Here, we create a new query named subin, add the table Orders, select the column Orders_Customer ID, and add a condition "Ship Via=Express Delivery" in the Search Condition dialog.
Now, the sub-query subin will be applied to the filter when you build a report that uses the Customers_Customer ID column.