(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 (DATEDIFF(e.data_a, e.data_da) > 3)
ORDER BY e.data_da,e.id ASC
LIMIT 1000,1000)