You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and a.cod_status_imovel = 1 and a.cod_negocio = 1 and a.cod_tipo = b.cod_tipo an' at line 6