[thelist] Stuck on SQL

Fred Jones fredthejonester at gmail.com
Fri Jul 24 06:10:58 CDT 2009

I have this:

SELECT civicrm_contact.id , COUNT(civicrm_entity_tag.tag_id)
 FROM civicrm_contact
 LEFT JOIN civicrm_entity_tag ON civicrm_entity_tag.contact_id =
 LEFT JOIN civicrm_tag ON civicrm_tag.id = civicrm_entity_tag.tag_id
 GROUP BY civicrm_contact.id;

which is good. I get results like

1  4
2  0
3  0
5  3

What I really want, however, is to get all contacts which do NOT have
a tag where the tag name is:

civicrm_tag.name LIKE "%Primary%"  OR civicrm_tag.name  LIKE "%Secondary%"

I don't care if he has zero tags or if he has 6 tags. I just care that
he has zero tags where the tag has "Primary" or "Secondary" somewhere
in its name.

I am not succeeding in figuring out how to do this with one SQL. :(


More information about the thelist mailing list