I have a contacts table like this:
Contacts
| CustomerID | CustomerName | Country |
|------------|------------------------------------|---------|
| 1 | Alfreds Futterkiste | Germany |
| 2 | Ana Trujillo Emparedados y helados | Mexico |
| 3 | Antonio Moreno Taquería | Mexico |
| 4 | Around the Horn | UK |
| 5 | Berglunds snabbköp | Sweden |
| 6 | Blauer See Delikatessen | Germany |
| 7 | Blondel père et fils | France |
| 8 | Bólido Comidas preparadas | Spain |
I have another table where all customer's exclusions are saved
Foreignkey is CustomerID
Relationship - one to many ...in exclusion table, there can be multiple rows for each customer (1 entry /per exclusion)
CustomerExclusion
| CustomerID | exclusion_type | Flag |
|------------|----------------|------|
| 1 | BadAddress | Y |
| 1 | Optout | Y |
| 3 | NoCall | Y |
| 4 | BadEmail | Y |
| 5 | BadAddress | Y |
Desired output:
Select all customers from customer table where county is 'Germany' but exclude anyone with 'BadAddress" and exclude anyone with 'Optout'