Filtering resultsets based on GROUP_CONCAT() generated value

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

  $if1 = "IF(s.student_ethnicity_interest_other IS NOT NULL AND
s.student_ethnicity_interest_other != '', " .
           "    CONCAT(s.student_ethnicity_interest_other, ', ',
GROUP_CONCAT(e.ethnicity_name ORDER BY upper(e.ethnicity_name))), " .
           '     GROUP_CONCAT(e.ethnicity_name ORDER BY
upper(e.ethnicity_name))' .
           "   ) AS ethnicity_name \n\n";

This segment of a larger SQL query produces a string that normally
looks like these:




Nordic peoples,caucasians


Here's the problem.  Requirement states that we now need to filter the
results by "ethnicity", which is a one-to-many relationship per

Let's say you have 20 applicants, and out of those, 1 of those has just
"caucasians" for ethnicity.

When you do the filter which I envision as:

WHERE ... AND ethnicity_name LIKE '%caucasians%'

Instead of having this value in the $result[$i]->ethnicity_name field
resultset value:


You see this:

caucasians,caucasians,caucasians,caucasians,caucasians..[repeated 7

Take out the filter and it displays just fine.

I am not sure how much more info I can provide; the query itself is
about 200 lines long and is under U.S. Government regulated security
(illegal to post it, sorry), unfortunately this is all I can think of
that is allowable to post that illustrates the problem.

Should note there there is an "ethnicity" table with 7 rows in it with
unique ethnicity names like "caucasians", "african-americans", etc.,
and a field in the "applicant" table that is
"applicant_ethnicity_interest_other" where you can enter whatever
ethnicity you want on top of the selected ethnicities in the
"ethnicity" table - if that helps.


Site Timeline