Select the table or query with the values you want to display in the query.
Specify the field that will join the records in the first table to the records in the second table.
The query displays those records in the Customers table that do not have any matching records in the tblCustomerTours table.
Some scenarios when you might need to create such a query include:
-
To find customers who have never placed an order.
-
To find products that have never been purchased.
-
To find "orphan" records. If you haven't enforced referential integrity in your related tables, deleting a record in one table could leave one or more orphan records in a related table. For example, if you delete a customer record from a Customer table, you may leave several for that customer in an Order table.
In this lesson you will use the Find Unmatched Query Wizard to create a query to find customers who have never booked a tour.
-
In the Database window, click the Queries icon in the Objects bar and click the New button.
The New Query dialog box appears.
-
Select the Find Unmatched Query Wizard and click OK.
The first step of the Find Unmatched Query Wizard appears, as shown in figure. You need to choose the table or query whose values you want to display in the query. Since you want to find customers without any tour packages, you would select the tblCustomers table.
-
Select the tblCustomers table and click Next.
The second step of the Find Unmatched Query Wizard appears. Here you have to tell Access which table contains the related records. Let's select the tblCustomerTours table.
-
Select the tblCustomerTours table and click Next.
The third step of the Find Unmatched Query Wizard appears, as shown in figure. Here you have to specify the related field to join the records in the first table to the records in the second table. Once you have selected the matching record in both tables, click the button to join the two tables.
-
Verify that the CustomerID field is selected in both tables and click the button.
The Matching fields area displays the fields used to join the tables (CustomerID = CustomerID).
-
Click Next.
Almost there! Now you have to specify which fields you want to see in the query.
-
Double-click the LastName, FirstName, City, and State fields.
The LastName, FirstName, City, and State fields should all appear in the "Selected fields" list.
-
Click Next.
Here you can give your query a nameor you can accept the default name that Access gives the query.
-
Click Finish.
Access saves the query with the name "tblCustomers Without Matching tblCustomerTours" and displays the results of the query, as shown in figure.
-
Close the query.
To use the find unmatched query wizard:
-
in the database window, click the queries icon in the objects bar and click the new button.
-
select find unmatched query wizard and click ok.
-
select the table whose values you want to display and click next.
-
select the table that contains the related records and click next.
-
specify the related fields that join the two tables, then click the button to join the two tables and click next.
-
double-click any additional fields that you want to appear in the query results and click next.
-
click finish.