Code that works for another app:
$commenters = $wpdb->get_results("SELECT COUNT($groupBy) AS comment_comments, comment_author, comment_author_url, comment_author_email
FROM $wpdb->comments AS co
INNER JOIN $wpdb->posts AS po
ON (co.comment_post_id = po.id AND post_status = 'publish' AND post_password = '')
INNER JOIN $wpdb->term_relationships AS tr
ON (co.comment_post_id = tr.object_id AND (tr.term_taxonomy_id in ($cat_children2)))
INNER JOIN $wpdb->term_taxonomy AS tt
ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND taxonomy = 'category')
WHERE comment_type != 'pingback'
AND comment_author != ''
AND comment_approved = '1'
$excludeNames
$listPeriod
$filterUrl
$filterEmail
$onlyWithUrl
GROUP BY $groupBy
ORDER BY comment_comments DESC, comment_author
");
Code that does not work:
$sql = "SELECT DISTINCT ID, post_title, post_password, post_status, comment_ID, comment_post_ID, comment_author, comment_author_url, comment_content, comment_date_gmt, comment_approved, comment_type, ";
if ($limit_by == "letters") {
$sql .= "SUBSTRING(comment_content,1,$bfa_rc_src_length) AS com_excerpt "; }
elseif ($limit_by == "words") {
$sql .= "SUBSTRING_INDEX(comment_content,' ',$bfa_rc_src_length) AS com_excerpt "; }
$sql .= "FROM $wpdb->growth_comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->growth_comments.comment_post_ID = $wpdb->growth_posts.ID)
LEFT OUTER JOIN $wpdb->growth_term_relationships AS tr
ON ((growth_comments.comment_post_ID = tr.object_id) AND (tr.term_taxonomy_ID in ($cat_children2)))
LEFT OUTER JOIN $wpdb->growth_term_taxonomy AS tt
ON (tr.term_taxonomy_ID = tt.term_taxonomy_ID AND taxonomy = 'category')
WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' AND post_status = 'publish'
ORDER BY comment_date_gmt DESC
LIMIT $bfa_rc_src_count";
$comments = $wpdb->get_results($sql);