This works, but it's huge.
We need to repeat each table column on each
UNION SELECT, as well as the
WHERE clause for
( SELECT GROUP_CONCAT(APA_T.district), t.name FROM tbl_activity AS t INNER JOIN tbl_activity_package AS ap ON t.id = ap.activity_id INNER JOIN ( SELECT DISTINCT apa.district AS district, ( SELECT s1.activity_package_id FROM tbl_activity_package_address s1 WHERE apa.district = s1.district ORDER BY s1.id DESC LIMIT 1 ) AS idActivityPackage FROM tbl_activity_package_address apa ORDER BY apa.district ) AS APA_T ON ap.id = APA_T.idActivityPackage WHERE (ap.publication_date <= CURDATE()) AND (DATE_ADD(ap.publication_date, INTERVAL ap.publication_duration_in_days DAY) >= CURDATE()) GROUP BY t.name ORDER BY APA_T.district ) UNION DISTINCT ( SELECT GROUP_CONCAT(DISTINCT apa2.district ORDER BY apa2.district), t2.name FROM tbl_activity AS t2 INNER JOIN tbl_activity_package AS ap2 ON t2.id = ap2.activity_id INNER JOIN tbl_activity_package_address AS apa2 ON ap2.id = apa2.activity_package_id WHERE (ap2.publication_date <= CURDATE()) AND (DATE_ADD(ap2.publication_date, INTERVAL ap2.publication_duration_in_days DAY) >= CURDATE()) GROUP BY t2.name ORDER BY apa2.district ) LIMIT 6, 6
I have removed the WHERE CLAUSE for DATE comparisons, because I can't have it on this fiddle structure, but, the repetition is still an issue. I've been told about INTERSECT but found nothing about that on MySQL.