[thelist] Stuck on SQL

Fred Jones fredthejonester at gmail.com
Fri Jul 24 09:18:38 CDT 2009


> Untested...
>
> SELECT civicrm_contact.id , COUNT(civicrm_entity_tag.tag_id)
> FROM civicrm_contact
> WHERE 1 > (
>        select count(*)
>        from civicrm_entity_tag
>        inner join civicrm_tag
>                on civicrm_tag.id = civicrm_entity_tag.tag_id
>        where civicrm_entity_tag.contact_id =
>                civicrm_contact.id
>                AND civicrm_tag.name LIKE "%Primary%"
>                OR civicrm_tag.name  LIKE "%Secondary%"
> );
>
> I didn't understand why you had left joins. Apologies if I missed a
> part of your logic...

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. :)



More information about the thelist mailing list