Solved

exclude records in one table from another table

Posted on 2006-06-29
6
1,163 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 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

12 Experts available now in Live!

Get 1:1 Help Now