?
Solved

exclude records in one table from another table

Posted on 2006-06-29
6
Medium Priority
?
1,230 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
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!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

650 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