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.aceptada=1 AND i.esKit!=3 AND o.enviada=1 AND o.cerrada=1 GROUP BY a.cen' at line 5