SELECT B.id AS idImmobile,B.Totale_mq,B.Prezzo_Richiesto,B.Locali FROM base AS B INNER JOIN categoria AS CAT ON CAT.idCategoria=B.idCategoria LEFT JOIN residenziali AS R ON B.id=R.id_Base INNER JOIN agenzie AS A ON A.id=B.id_agenzia WHERE A.attivo='1' AND (B.id_agenzia = '1') ORDER BY rand()