Invalid query: 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 'group by c.ctc_cod' at line 1 select c.ctc_cod, c.ctc_dtinicio, c.ctc_dtfim, c.ctc_hrfim, c.ctc_nom_obs, fn4.fn4_desc from cotacao c inner join cotacao_forn cf on c.ctc_cod = cf.ctc_cod and c.ctc_empresa = cf.ctc_empresa inner join cg2 f on cf.cg2_cod = f.cg2_cod inner join fn4 on fn4.fn4_cod = f.cg2_codcondpag WHERE c.ctc_cod = '' and cf.cg2_cod = '' and c.ctc_empresa = group by c.ctc_cod