Link to home
Start Free TrialLog in
Avatar of mhuang121
mhuang121Flag for United States of America

asked on

Problem with querying record with multiple records in a joined table

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.
ASKER CERTIFIED SOLUTION
Avatar of joeyw
joeyw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mhuang121

ASKER

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!