string(585) " FROM Tabvereador V inner join tablegislaturavereador L on (L.NPessoa = V.IdVereador) inner join tabcargo C on (C.IdCargo = L.NCargo) inner join tabvinculo Vi on (Vi.IdVinculo = L.NVinculo) left join(select * from tabfiliapartido where ((DataFim > CURDATE()) OR (DataFim IS NULL))) F ON (F.NAgente = V.IdVereador) left join tabpartidos P ON (P.IdPartidos = F.NPartido) where L.NVinculo IN ('1','2','3','6') AND ((L.VTipo = 'V') OR (L.VTipo IS NULL)) AND L.NLegislatura = :leg GROUP BY IdVereador HAVING MAX(L.DataFim) "