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 i.idimob=1 and (r.idimovel=i.id and r.idtipo=i.idtipo) and i.idtipo=t.id an' at line 1