SELECT s.id, s.student_first_name, s.student_last_name,
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
FROM student s, completion_comments cc, ethnicity e, student_ethnicity_interest_assoc seia
WHERE s.id = seia.student_id
AND seia.ethnicity_id = e.id
If I run this query, I do not get all of the results I want, because of a bizarre data mangling problem:
In student_ethnicity_interest_assoc you can literally have a record like this:
student_id ethnicity_id
810 0
There is no ID of 0 in ethnicity, thus, the join fails and the record never shows up, but if I try to join on the ethnicity_id being 0, then I get a runaway process, Apache, MySQL, everything crashes!
But if I take that very same record out, that record does not appear even though it should.
I'm at a loss as to how to fix this. Please help!
Thanx
Phil