When filtering the fields of a query with the filter format, you are also enabled to use sub-queries to narrow down the result. 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 subquery when filtering a field:
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 subquery subin will be applied to the filter when you build a report that uses the Customers_Customer ID column.