How to determine if a record is not present (2 Viewers)

Gkirkup

Registered User.
Local time
Yesterday, 23:58
Joined
Mar 6, 2007
Messages
628
I have a query which shows records from a table. Then I have a second table linked by a common field, with a criteria. The criteria that I want to use for a record is that a linked record in the second table is NOT present, OR if it is present, then a field value in that record is 4 or 5.
I have no problem with the 4 or 5, but how do I have a criteria in my query based on whether a record in the linked table is present or not present?

Robert
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:58
Joined
Aug 30, 2003
Messages
36,127
Sounds like the unmatched query wizard will help.
 

Gkirkup

Registered User.
Local time
Yesterday, 23:58
Joined
Mar 6, 2007
Messages
628
Paul: I am not familiar with that. What is it?

Robert
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:58
Joined
Feb 28, 2001
Messages
27,222
Build a relationship between your two tables, call them A and B for the moment, based on that common field. A is the one that is the base of your query; B is the one that might not be there sometimes. Therefore, the relationship will be for "every record in A and every matching record in B." This is in essence a "one-to-many" type of relationship, but you REALLY want that option because this is NOT a one-to-one relationship (due to B sometimes being absent.)

I'm going to assume that you never have the case where you have one A record and many matching B records. Your description at least implied that B was SPARSE with respect to A.

Now build a query using the query grid builder with those two tables participating. Because you have the relationship defined first, the query builder will honor it and make the correct kind of JOIN for you, which (I'm guessing) will be a LEFT OUTER JOIN on the common field.

In this query, include the required fields for your tests and computations or whatever you are doing. But include the common field from B using the construct where you put an alternate field name followed by a colon followed by the field you wanted from the B table. The grid for that field might have [BCommon: Common] in it (but of course you use the correct name for your field.)

Now you can write a query based on this JOIN query and tell it you want to see records where your test field = 4 or test field = 5 or IsNull(BCommon) = true.
 

Users who are viewing this thread

Top Bottom