Solved

Problem with querying record with multiple records in a joined table

Posted on 2009-05-13
2
182 Views
Last Modified: 2012-05-06
We have two tables, Names and Prefs. Prefs have fields ID (key back to Names), method and request. This is how we track the Do Not Contact lists. Someone can have method = 'Fax' and request = 'Opt-Out' and when we pull a query for fax, this person will be skipped.

The problem is a person may have more than one Prefs record for other requests like Opt-Out of Email and Opt-In Phone etc. So for same person in Names table there may be mulitple Prefs table records.

So, when we set up a SQL query joining the Names and Prefs tables together by ID, we can put in a WHERE statement of method<>'Fax' and request<>'Opt-Out' but it will still pull the Names record if there is another entry in the Prefs table.

So, not sure how to word this question. But how do we pull a query with 2 tables (Names and Prefs) where we don't want the Names record if it has specific record in Prefs table (i.e. Opt-Out of Fax), barring all other Prefs records attached to that Names record?

Thanks in advance.
0
Comment
Question by:mhuang121
2 Comments
 
LVL 4

Accepted Solution

by:
joeyw earned 500 total points
ID: 24374418
Try this:

Select * from names as A
where id not in (select id from prefs as b where a.id=b.id and  method='Fax' and request='Opt-Out' )
0
 

Author Closing Comment

by:mhuang121
ID: 31580952
Thank a lot for the solution! I was trying to use the not in function but forgot the id=id check in the subquery. Thanks again!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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