((SELECT *,e.id as id_foto_ok FROM cataloghi_foto as e
LEFT JOIN foto_aggiuntive as b on e.id = b.id_foto
LEFT JOIN prodotto as c on c.id_foto = e.id
WHERE c.id_azienda = '1'
AND e.tipo_prod = '1'
AND b.ordine = (SELECT MIN(ordine) from foto_aggiuntive as d WHERE d.id_foto = b.id_foto)
AND e.se_attivo = '1'
AND e.data_da >= CURDATE()
AND e.tipo_disponibilita = '5'
ORDER BY e.data_da,e.id ASC
LIMIT 18) UNION
(SELECT *,e.id as id_foto_ok FROM cataloghi_foto as e
LEFT JOIN foto_aggiuntive as b on e.id = b.id_foto
LEFT JOIN prodotto as c on c.id_foto = e.id
WHERE c.id_azienda = '1'
AND e.tipo_prod = '1'
AND b.ordine = (SELECT MIN(ordine) from foto_aggiuntive as d WHERE d.id_foto = b.id_foto)
AND e.se_attivo = '1'
AND e.se_cs = '1'
AND e.tipo_disponibilita = '5'
ORDER BY e.mese_cs ASC)) ORDER BY data_da,se_cs ASC