diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 7e6e097571..51a45166ba 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -1529,7 +1529,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
 					FROM ' . TOPICS_TABLE . ' t
 					WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
 						AND t.topic_approved = 1
-					GROUP BY p.forum_id';
+					GROUP BY t.forum_id';
 			}
 
 			$result = $db->sql_query($sql);