Okay, this has kept me busy for the past couple of days and just about had enough of it. What I'm trying to do is build Mailing Lists using logic instead of just assigning a contact to a mailing list. I've tried and tried but got no where as I think the solution is outside my knowledge scope of SQL.

The reason why I need this is because my client would sometimes like to target a subset of all their contacts and it needs to be dynamic so new contacts can be automatically included/excluded.

So here are the tables ...

Code:
tblCountry
CountryId    CountryName
-------------------------------------
1            United Kingdom
2            United States of America
3            Canada
4            Austria

tblReligion
ReligionId   ReligionName
--------------------------------------
1            Christian
2            Sikhism
3            Athiest

tblContact
ContactId    ContactName       CountryId    ReligionId
------------------------------------------------------
1            John Smith        1            NULL
2            Jane Roberts      1            1
3            Tim Williams      1            1
4            John Doe          2            2
5            Janice McBride    2            3
6            Eddie Lewis       3            NULL
7            Hans Murdoch      4            1

tblRecipientGroup
RecipientGroupId    RecipientGroupName
--------------------------------------
1                   European Christians
2                   All Athiests
3                   No Christians

tblRecipientItem
RecipientItemId    RecipientGroupId    CountryID    ReligionID    IsExclude
---------------------------------------------------------------------------
1                  1                   1            NULL          0
2                  1                   4            NULL          0
3                  1                   NULL         1             0
4                  2                   NULL         3             0
5                  2                   NULL         1             1

Note: IsExclude detemines if the country is excluded instead of the default (included)
... and in brief, If I wanted to obtain all European Christians then 3 items are added to tblRecipientItem to represent the countries and religion to filter on. So the results would look like so ...

Code:
tblContact
ContactId    ContactName       CountryId    ReligionId
------------------------------------------------------
2            Jane Roberts      1            1
3            Tim Williams      1            1
7            Hans Murdoch      4            1
... but bear in mind that that we may want to exclude filters like the No Chistians mailing list in tblRecipientGroup.

How would I go about building a query for this?