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.ID )x INNER JOIN ubicacion u ON u.ID = x.ID )z JOIN valoracion w ON ' at line 1