Mysql
 sql >> Database >  >> RDS >> Mysql

GROUP_CONCAT e INNER JOIN con clausola WHERE

Il WHERE la clausola limita i record precedenti al raggruppamento; mentre il HAVING la clausola limita i risultati dopo raggruppamento:

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')

Guardalo su sqlfiddle .