Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem with querying record with multiple records in a joined table

Posted on 2009-05-13
2
Medium Priority
?
191 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
[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
2 Comments
 
LVL 4

Accepted Solution

by:
joeyw earned 2000 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

Technology Partners: 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!

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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