Solved

exclude records in one table from another table

Posted on 2006-06-29
6
1,187 Views
Last Modified: 2011-04-06
I have a table with certain customers that should be excluded from mailing.  How do I join the full table to this table to provide a list with just those who should get the mailing?  Thank you in advance for your help.
0
Comment
Question by:clballas
  • 3
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 500 total points
ID: 17008769
SELECT *
FROM tblCustomers
WHERE CustomerID Not In (SELECT CustomerID FROM tblCostNoMail)

or

SELECT *
FROM tblCustomers
    LEFT JOIN tblCostNoMail ON tblCustomers.CustomerID = tblCostNoMail.CustomerID
WHERE tblCostNoMail.CustomerID Is Null
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17008816
Perfect SQL from LPurvis

An alternative idea

Why dont u have a flag on your main table. This indicates whether they get included or not

Then u can just use this flag value


Doesnt answer your question but gives an alternative design and so the SQL is easier for you.

Oh well
0
 

Author Comment

by:clballas
ID: 17044450
LPurvis,

Both ways seem to work.  Any reason to choose one over the other?

--clballas

0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17044497
Opinion varies.
There's every chance that Jet would create an execution plan the same way for either.
It used to be felt that the Join would operate more efficiently - but as stated above this isn't necessarily so.
(I can't remember testing in recent history - but as a general rule I'll prefer the Join... and use In when it's required).

Simple answer - run them both - see if one's slightly faster. :-)
(It could well vary from recordset to recordset).
0
 

Author Comment

by:clballas
ID: 17050810
Outstanding, clear answer! Thanks so very much!
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17053123
You're very welcome.  :-)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question