SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with count and Join

    I have this SQL query here:

    PHP Code:
    SELECT wp_posts.*, wp_postmeta.* FROM wp_postswp_postmeta WHERE wp_posts.ID=wp_postmeta.post_id  AND meta_key='image_path'  group by ID desc 
    however I would like to get the count total from this how can I do it?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what exactly is it that you want to count?

    what table does the ID in your GROUP BY clause belong to?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    what exactly is it that you want to count?

    what table does the ID in your GROUP BY clause belong to?

    I want to count the number of times the query finds a match from both tables, the ID I'm talking about is from wp_posts.ID

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    do you want the count for each ID, or the total count overall?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    do you want the count for each ID, or the total count overall?
    the total count for each ID

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT post_id
         , COUNT(*)
      FROM wp_postmeta 
     WHERE meta_key = 'image_path'  
    GROUP 
        BY post_id DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Code:
    SELECT post_id
         , COUNT(*)
      FROM wp_postmeta 
     WHERE meta_key = 'image_path'  
    GROUP 
        BY post_id DESC

    actually it didn't give the proper result I was looking for can you please show me the query for the total count overall?

    thanks

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Sinz View Post
    ...can you please show me the query for the total count overall?
    Code:
    SELECT COUNT(*)
      FROM wp_postmeta 
     WHERE meta_key = 'image_path'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •