Title: SELECT COUNT(*)
Last modified: August 21, 2016

---

# SELECT COUNT(*)

 *  Resolved [bst](https://wordpress.org/support/users/bst/)
 * (@bst)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/select-count/)
 * Can you please point me in the right direction. I have a SQL query and it works.
 *     ```
       SELECT
       p.post_title,
       m1.meta_value
       AS footballteam_value
       FROM wp_posts
       AS p
       LEFT JOIN wp_postmeta AS m1 ON m1.post_id = p.ID AND m1.meta_key = 'footballteam_value'
       WHERE p.post_type = 'team'
       AND post_status = 'publish'
       GROUP BY m1.meta_value
       ```
   
 * The report shows me all my different football teams
 * I am now trying to count how many posts there are with this football team
 * I am guessing I need to use the “SQL Query for Count” so that I can add a column
   to the report with the sum of how many posts with this football team?
 * So far I have this but its not working, I just get zeros in the column
 *     ```
       SELECT COUNT(*)
       FROM $wpdb->posts p, $wpdb->postmeta p1
       WHERE p.post_status = 'publish' AND p.ID = p1.post_id
       AND p1.meta_key = 'footballteam_value'
       AND p1.meta_value = '$item'
       ```
   
 * I have also added the field name of $item, with data type number…..
 * Any help would be much appreciated….
 * Many Thanks
 * [http://wordpress.org/extend/plugins/exports-and-reports/](http://wordpress.org/extend/plugins/exports-and-reports/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Scott Kingsley Clark](https://wordpress.org/support/users/sc0ttkclark/)
 * (@sc0ttkclark)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/select-count/#post-3948140)
 * Exports and Reports automatically handles counting calculations, that’s for advanced
   usage that involve large queries that have subqueries.

Viewing 1 replies (of 1 total)

The topic ‘SELECT COUNT(*)’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/exports-and-reports.svg)
 * [Exports and Reports](https://wordpress.org/plugins/exports-and-reports/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/exports-and-reports/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/exports-and-reports/)
 * [Active Topics](https://wordpress.org/support/plugin/exports-and-reports/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/exports-and-reports/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/exports-and-reports/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Scott Kingsley Clark](https://wordpress.org/support/users/sc0ttkclark/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/select-count/#post-3948140)
 * Status: resolved