English 中文(简体)
Unmatched Query Wizard
  • 时间:2024-11-03

MS Access - Unmatched Query Wizard


Previous Page Next Page  

In Access, there is another very useful wizard and that is Find Unmatched Query Wizard. The Find Unmatched Query Wizard creates a query that finds records or rows in one table that have no related records in another table.

As we have already discussed how data joins together in queries, and how most queries are looking for the matches between two or more tables.

Matched

    This is the default join in Access, for example, if we design a query with two tables, tblCustomers and tblOrders, and join those two tables by the CustomerIDs, this query will return only the results that match. In other words, the customers who have placed orders.

    There are times when we don t want to see the matches, for instance, we may not want to see any customer in our database — the customers who have not placed orders as yet.

Not Placed Orders

    This is exactly what the find unmatched query does.

There are many other possible uses for this kind of query as well.

In our database, we can use it to see which authors have not yet written a project or you could use it to see which employees have not yet elected any health benefits. Let us now open your database which contains Customers and Orders table; go to the Create tab and cpck on the query wizard button.

Select the Find Unmatched Query Wizard and cpck Ok.

Unmatched

In this scenario, we will look out for those customers who have not placed an order. In the first screen it s asking which table or query contains the records you want in the query results.

We now want a pst of customers from tblCustomers. Select that option and cpck Next.

Customers Table

In the following screen, you need to specify which table or query contains the related records. In other words, what table are you using to compare with the first one. For this, we need to find the ones that have not placed orders. We need to select the table that contains information on all orders — tblOrders. Now, cpck Next.

TblOrders

In the following screen, you need to specify which piece of information is in both tables.

    This will typically be some kind of primary key, foreign key, field, or relationship.

    If you have an existing relationship in your database, Access will select and match those fields for you.

    But, if you have other fields that you can join together, contain similar information, you can choose that here as well.

Here, we have CustID selected by default in both Fields in ‘tblCustomers’ and Fields in ‘tblOrders’. Now, cpck Next.

CustID

In the following screen, you can pick and choose the fields you want to see displayed in the query results.

Selected Files

Let us now select all the available fields and cpck on the double-headed arrow. This moves all the available fields over to the selected fields area. Now, cpck Next.

First Order

The last screen will allow you to choose a name for your query and cpck Finish.

Without Matching

Here we have one customer psted as that customer who has not placed an order with us yet.

Customer Listed

You can also see how that query was created. For this, you need to go back to the Design View.

Is Null

This wizard has created an Outer Join between tblCustomer and tblOrders and the Is Null criteria is added to the CustID from tblORders. This is to exclude certain records. In this case, it is the customers who have placed orders, or who have related information in tblOrders.

Advertisements