Solved

exclude records in one table from another table

Posted on 2006-06-29
6
1,172 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now