querying records with no corresponding value in related table

G

Guest

I'm having one of those days. Here's the trouble: I have a table of names
(let's call it tblNames) and a related table of log entries (let's call it
tblLog) which correspond to those names. Some names have no log entries
while others have many. I want to query tblNames for all the entries that
have no log entries in tblLog. I'm sure I've done it before and I think it
was even pretty easy but I'm having a senior moment this afternoon and I
could use a hand with the sql statement for this. In case it's helpful
here's how the data currently looks:

Tables:
tblNames.ID_Names (Integer - Autonumber - Key)
tblNames.FirstName (text)
tblNames.LastName (text)

tblLog.ID_Log (Integer - Autonumber - key)
tblLog.Match (integer)
tblLog.Entry (memo)

Relationship:
One-to-Many tblName.ID_Names to tblLog.Match

Your help will be greatly appreciated! Thanks!
 
D

Douglas J. Steele

You need to do a left join. If you're using the graphical query builder,
select the line that joins the two tables and right-click. You should get
two choices in the context menu that appears: Join Properties, and Delete.
Select Join Properties, and choose the option that'll give you "Include ALL
records from 'tblNames' and only those records from 'tblLog' where the
joined fields are equal."
 
G

Guest

Ah! Fantastic! That is precisely what I was trying and failing to remember.
worked like a charm. I was able to change the join properties so it showed
me both records with corresponding log entries and records without and then I
added the criteria of "null" to the log entry and it reduced my query results
to just those records that had no log entries. Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top