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_grupo = b.cod_grupo and a.cod_subgrupo = c.cod_subgrupo and b.cod_grup' at line 1