Need help writing ColdFusion sql query with a JOIN

Queries that use a join always baffle me so I could use some expert advice. Thanks in advance...

How to I write a ColdFusion query where:

I have one database called "Visitors"

I have 2 tables in that database:
"Users" is a table with my entire membership listing
"EmailSent" is a table listing every newsletter sent to each member

The common field is "UserID"

Within EmailSent is a field called "TemplateUsed" which is a different template for each version of the newsletter.

I need a query that will output the UserID's of those members who did not yet receive a particular template called "ImportedCareerCoach5.cfm"

But they may have received other newsletters.

Hope that makes sense.

 I'm running CF 10 and MS SQL
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:

select a.* from Users a
left join 
(select * from EmailSent where TemplateUsed = 'ImportedCareerCoach5.cfm' ) b
on a.UserID = b.UserID
where b.UserID is null

Open in new window

this will do it ..

select a.* 
from Users a
where not exists (
   select 1
   from EmailSent em
   where em.user_id = a.user_id
   and   sm.TemplateUsed = 'ImportedCareerCoach5.cfm'

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bigmikey88Author Commented:
Thank you GDEMARIA, that worked.

Sorry for such a late reply.  I started working with your solution right away, but was getting odd results, which took a lot of analysis.  
but it's working now in production.

Thank you Ryan Chong.  Sorry I did not get to try your solution, but I will use it next time to see how it works.

Thanks to all of you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.