Skip to content
Advertisement

Access Query mysteriously omitting records

I have an MS Access Contact & Correspondence database consisting of a “Contacts” table (Name, phone, email, etc.) and a “Calls” table (Contact, Incoming/Outgoing, Time, Medium, Notes, etc.). The tables are linked on Contacts.ID = Calls.Contact

For example:

I’m trying to build a query to report all the contacts information (just as when the table is opened up directly), but with a field showing the most recent Incoming and Outgoing correspondence.

So, for the above data:

So the results would independently identify the latest date of a correspondence record of both the incoming and outgoing types, and would return [nulls] wherever such a correspondence type did not yet exist.

I have a query that is working, mostly. However it seems to be mysteriously omitting certain records for which there are no records in ‘Calls’. Not all such records, mind you.

My existing, troubled code is shown below. I have also tried moving the WHERE statements inside the JOINS (before ON); I have tried opening the WHERE statement with Calls.Time IS NULL OR Calls_1.Time IS NULL OR … , and several other versions of the WHERE statement.

Here is the existing query:

The full ‘Contacts’ table has 361 records. The intended result is that all 361 records will be returned, whether they have corresponding records in ‘Calls’ or not.

In fact only 208 records are returned. Many of these do not have corresponding ‘Calls’ records, telling me that the OR NULL statements are working, at least partly. I cannot find any consistent distinction between the records that are omitted verses the records that are returned.

Advertisement

Answer

Do the aggregation before doing the JOIN. Then you only need to aggregate once:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement