WHERE
klausul begränsar poster tidigare till gruppering; medan HAVING
klausul begränsar resultat efter gruppering:
SELECT course.id, course.name, GROUP_CONCAT(Flag.id) flags
FROM course
JOIN course_flags ON course_flags.course_id = course.id
JOIN flag ON flag.id = course_flags.flag_id
GROUP BY Course.id
HAVING SUM(flag.name = 'promocja')
Se den på sqlfiddle .