?
Solved

exclude records in one table from another table

Posted on 2006-06-29
6
Medium Priority
?
1,217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

770 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