(select D.field_id_28 as subtitle, L.cat_id as languageCat, P.field_id_4 as imgSrc, T.url_title, C.cat_id, T.entry_id, T.title, D.field_id_1 as short_description, MIN(D.field_id_31) as start_date, MAX(D.field_id_32) as end_date from
exp_channel_titles T
LEFT JOIN exp_channel_data D on T.entry_id = D.entry_id and FROM_UNIXTIME(D.field_id_31,'%Y-%m-%d') > DATE_SUB(NOW(), INTERVAL 14 DAY)
JOIN exp_category_posts C on T.entry_id = C.entry_id and C.cat_id <> 39 and C.cat_id <> 45 and C.cat_id <> 44
JOIN exp_category_posts L on T.entry_id = L.entry_id and (L.cat_id = 44 OR L.cat_id = 45)
LEFT OUTER JOIN exp_relationships I on I.parent_Id = T.entry_id and I.field_id = 6
LEFT OUTER JOIN exp_channel_data P on P.entry_id = I.child_id
where D.field_id_31 <> 0 and T.channel_id = 7 group by entry_id) UNION
(select D.field_id_28 as subtitle, L.cat_id as languageCat, P.field_id_4 as imgSrc, T.url_title, C.cat_id, T.entry_id, T.title, D.field_id_1 as short_description, MIN(M.col_id_3) as start_date, MAX(ED.col_id_3) as end_date from
exp_channel_titles T
LEFT JOIN exp_channel_data D on T.entry_id = D.entry_id
LEFT OUTER JOIN (SELECT entry_id,col_id_3 FROM exp_matrix_data ORDER BY col_id_3 ASC) M on M.entry_id = T.entry_id and FROM_UNIXTIME(M.col_id_3,'%Y-%m-%d') > DATE_ADD(NOW(), INTERVAL -1 DAY)
LEFT JOIN (SELECT entry_id,col_id_3 FROM exp_matrix_data ORDER BY col_id_3 DESC) ED on ED.entry_id = T.entry_id
JOIN exp_category_posts C on T.entry_id = C.entry_id and C.cat_id <> 39 and C.cat_id <> 45 and C.cat_id <> 44
JOIN exp_category_posts L on T.entry_id = L.entry_id and (L.cat_id = 44 OR L.cat_id = 45)
LEFT OUTER JOIN exp_relationships I on I.parent_Id = T.entry_id and I.field_id = 6
LEFT OUTER JOIN exp_channel_data P on P.entry_id = I.child_id
where M.col_id_3 <> 0 and T.channel_id = 9
group by T.entry_id order by start_date ASC) order by start_date;