[thelist] Stuck on SQL

Jason Handby jason.handby at corestar.co.uk
Fri Jul 24 09:45:02 CDT 2009

> That was just the code the last guy had. If we remove the first COUNT
> from your select, then it runs, but it brings no results, whether I
> use 1 > or 1 =. I know, BTW, that there are results to what I want. :)
> Thanks however. I will keep working on it. Now I have more ideas
> anyhow. :)

If you just want those contacts who have no tags containing "Primary" or
"Secondary", and you don't need the tag count, something like this
should work:

SELECT civicrm_contact.id FROM civicrm_contact WHERE NOT EXISTS
  (SELECT * FROM civicrm_entity_tag INNER JOIN civicrm_tag
    ON civicrm_entity_tag.tag_id=civicrm_tag.id
    WHERE civicrm_entity_tag.contact_id=civicrm_contact.id AND
    (civicrm_tag.name LIKE "%Primary%"
      OR civicrm_tag.name LIKE "%Secondary%"))


More information about the thelist mailing list