getQuery() returns: SELECT z.id, z.pid, z.uid, z.recurrence_id, z.sequence, z.event_type, z.event_start, z.event_end, z.event_rstart, z.event_rend, z.icalrule, z.exdate, z.tzid, z.article_id, z.transp, z.status, z.created, z.created_by, z.modified, z.modified_by, z.published, z.approved, z.private, z.created as datestamp,CASE WHEN (private > 0 AND z.created_by <> 0) THEN "Private Event" ELSE z.title END AS title,CASE WHEN (private > 0 AND z.created_by <> 0) THEN "" ELSE z.location END AS location,CASE WHEN (private > 0 AND z.created_by <> 0) THEN "" ELSE z.content END AS content,CASE WHEN (private > 0 AND z.created_by <> 0) THEN null ELSE z.lid END AS lid,CASE WHEN (private > 0 AND z.created_by <> 0) THEN null ELSE z.latitude END AS latitude,CASE WHEN (private > 0 AND z.created_by <> 0) THEN null ELSE z.longitude END AS longitude,CASE WHEN (private > 0 AND z.created_by <> 0) THEN null ELSE z.params END AS params,CASE WHEN (private > 0 AND z.created_by <> 0) THEN null ELSE z.contact END AS contact,c.title AS category, c.params AS catparams, c.id as catid, c.lft,ec.catids, ec.categories FROM (SELECT uid, catid, group_concat( catid ORDER BY c.lft ASC SEPARATOR "," ) AS catids, group_concat( c.title ORDER BY c.lft ASC SEPARATOR ", " ) AS categories FROM #__zcalendar_event_categories ec2, #__zcalendar_categories c WHERE ec2.catid = c.id AND ec2.catid in (2,14,17,16,18,19,20,21,22,23,13,12,3,4,5,6,7,8,9,10,11,24) AND c.published > 0 GROUP BY uid order by c.lft desc) AS ec LEFT JOIN #__zcalendar_events AS z on (id) LEFT JOIN #__zcalendar_categories AS c on c.id = ( select id from #__zcalendar_categories c where c.id in (catids) order by c.lft desc ) LEFT JOIN #__zcalendar_locations AS l ON l.id = z.lid WHERE z.uid = ec.uid AND z.published > 0 AND z.approved > 0 AND z.access in (1,1,5) AND c.access in (1,1,5) AND ((z.event_start >= '2016-08-20 00:00:00' AND z.event_start <= '2016-08-28 23:59:59') OR (z.event_end >= '2016-08-20 00:00:00' AND z.event_end <= '2016-08-28 23:59:59') OR (z.event_start <= '2016-08-20 00:00:00' AND z.event_end >= '2016-08-28 23:59:59')) ORDER BY c.lft desc,z.event_start ASC