Title: Custom query help
Last modified: August 19, 2016

---

# Custom query help

 *  [callmeforsox](https://wordpress.org/support/users/sunscream/)
 * (@sunscream)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/custom-query-help/)
 * Wondering if anyone can help with a custom query of mine. It’s a recent comments
   query. It basically gets the recent comments and groups them by posts so it doesn’t
   show duplicate posts when I print it in a list. The problem is the query has 
   been overloading mysql on my server. Can anyone see a better more efficient way
   to do it?
 *     ```
       $request = "SELECT ID, comment_ID, comment_content, comment_date, comment_author, comment_author_url, post_title FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE post_status IN ('publish','static') ";
   
       $request .= "AND comment_approved = '1' GROUP BY $wpdb->posts.ID ORDER BY comment_date DESC LIMIT $number";
       ```
   

The topic ‘Custom query help’ is closed to new replies.

## Tags

 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * 0 replies
 * 1 participant
 * Last reply from: [callmeforsox](https://wordpress.org/support/users/sunscream/)
 * Last activity: [16 years, 8 months ago](https://wordpress.org/support/topic/custom-query-help/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
