Query failed! 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 gameMessage) UNION ALL (SELECT 1 AS myMessage, gameMessage, count(*) as' at line 2

Backtrace:
Array ( [0] => Array ( [file] => /home/chessman/public_html/webchess/includes/classes/Database.class.inc [line] => 78 [function] => read_query [class] => Database [object] => Database Object ( [queries:protected] => Array ( ) [read_count:protected] => 1 [write_count:protected] => 0 ) [type] => -> [args] => Array ( [0] => (SELECT 1 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= GROUP BY gameMessage) UNION ALL (SELECT 1 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= GROUP BY gameMessage) UNION ALL (SELECT 0 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= GROUP BY gameMessage) UNION ALL (SELECT 0 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= GROUP BY gameMessage) UNION ALL (SELECT 1 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= ) UNION ALL (SELECT 1 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= ) UNION ALL (SELECT 0 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= ) UNION ALL (SELECT 0 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= ) UNION ALL (SELECT NULL AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) AND (gameMessage = 'playerInvited' OR gameMessage = '') AND blackPlayer= GROUP BY gameMessage) UNION ALL (SELECT NULL AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) AND (gameMessage = 'playerInvited' OR gameMessage = '') AND whitePlayer= GROUP BY gameMessage) [1] => [2] => 15 [3] => ) ) [1] => Array ( [file] => /home/chessman/public_html/webchess/includes/chessdb.php [line] => 1919 [function] => query [class] => Database [object] => Database Object ( [queries:protected] => Array ( ) [read_count:protected] => 1 [write_count:protected] => 0 ) [type] => -> [args] => Array ( [0] => (SELECT 1 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= GROUP BY gameMessage) UNION ALL (SELECT 1 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= GROUP BY gameMessage) UNION ALL (SELECT 0 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= GROUP BY gameMessage) UNION ALL (SELECT 0 AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= GROUP BY gameMessage) UNION ALL (SELECT 1 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= ) UNION ALL (SELECT 1 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= ) UNION ALL (SELECT 0 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'white' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and blackPlayer= ) UNION ALL (SELECT 0 AS myMessage, 'flag' AS gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 AND gameMessage='playerResigned' AND flagFall = 1 AND messageFrom = 'black' and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) and whitePlayer= ) UNION ALL (SELECT NULL AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) AND (gameMessage = 'playerInvited' OR gameMessage = '') AND blackPlayer= GROUP BY gameMessage) UNION ALL (SELECT NULL AS myMessage, gameMessage, count(*) as cnt FROM games WHERE gameType = 0 AND oficial = 1 and timelimit >= 1440 and team>0 AND lastMove > date_sub(NOW(),INTERVAL 365 DAY) AND (gameMessage = 'playerInvited' OR gameMessage = '') AND whitePlayer= GROUP BY gameMessage) ) ) [2] => Array ( [file] => /home/chessman/public_html/webchess/team_match_join.php [line] => 205 [function] => getStatsUserTeam [args] => Array ( [0] => [1] => 1 [2] => 0 [3] => 365 ) ) )