I'm building a View that lists contacts. The View needs to list all contacts that are not tagged with a certain tag. The problem is if a contact is tagged with another tag, it will still show in the list, because of the LEFT JOIN to the tag table...In this example I'm filtering the list to one contact for simplicity's sake. The contact in question has two tags. One of them is the one I want to filter out. Yet the contact still shows in the list because it has another tag....
I also want to include contacts in the list that have no tags at all, thus the
part of the query ( (civicrm_tag.id IS NULL ) OR (civicrm_tag.id NOT IN ('35')) )
SELECT civicrm_contact.id AS id, civicrm_contact.display_name AS civicrm_contact_display_name
FROM
{civicrm_contact} civicrm_contact
LEFT JOIN {civicrm_entity_tag} civicrm_entity_tag ON civicrm_contact.id = civicrm_entity_tag.entity_id AND civicrm_entity_tag.entity_table = 'civicrm_contact'
LEFT JOIN {civicrm_tag} civicrm_tag ON civicrm_entity_tag.tag_id = civicrm_tag.id
WHERE (( (civicrm_contact.id = '21033') )AND( (civicrm_tag.id IS NULL ) OR (civicrm_tag.id NOT IN ('35')) ))
LIMIT 10 OFFSET 0