Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:33:14+00:00 2026-06-17T20:33:14+00:00

SELECT b.post_title , a.post_id , Deriv1.Count FROM wp_posts b , wp_postmeta a LEFT OUTER

  • 0
SELECT b.post_title
     , a.post_id
     , Deriv1.Count
FROM  wp_posts b
    , wp_postmeta a
LEFT OUTER JOIN (    
   SELECT meta_value, COUNT( * ) AS Count
   FROM  wp_postmeta
   GROUP BY meta_value
   ) Deriv1 
ON a.post_id = Deriv1.meta_value
WHERE a.meta_value = 1
  AND a.meta_key = 'type-select' 
  AND b.post_status = 'publish'
  and post_type = 'car-cc'

Current problem of the SQl STATEMENT is when i supply meta_value =1 it is fetching all values i.e. post_id which do not have meta_value =1 is also listed.

http://sqlfiddle.com/#!2/1115a7/1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:33:15+00:00Added an answer on June 17, 2026 at 8:33 pm

    I think the problem is you’re not joining on the wp_posts table and wp_postmeta table. Add this to your WHERE clause:

    AND a.post_id = b.ID
    

    Alternatively, just do an INNER JOIN on the two tables:

    SELECT b.post_title
         , a.post_id
         , Deriv1.Count
    FROM  wp_posts b INNER JOIN 
            wp_postmeta a ON a.post_id = b.ID
    LEFT OUTER JOIN (    
       SELECT meta_value, COUNT( * ) AS Count
       FROM  wp_postmeta
       GROUP BY meta_value
       ) Deriv1 
    ON a.post_id = Deriv1.meta_value
    WHERE a.meta_value = 1
      AND a.meta_key = 'type-select' 
      AND b.post_status = 'publish'
      and post_type = 'car-cc'
    

    BTW — Did you want the count for each group? If so, your query can be simplified:

    SELECT b.post_title, a.post_id, COUNT( * ) as Total
    FROM  wp_posts b INNER JOIN 
                wp_postmeta a ON a.post_id = b.ID
        WHERE a.meta_value = 1
          AND a.meta_key = 'type-select' 
          AND b.post_status = 'publish'
          and post_type = 'car-cc'
    GROUP BY b.post_title, a.post_id
    

    Here is some updated fiddle. Wasn’t sure of your desired output.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a query... SELECT p.* FROM wp_posts p JOIN wp_postmeta pm ON pm.post_id
Original SQL query is this; SELECT id,post_title,post_date FROM wp_posts where id='1' When I retrieve
Here's my query SELECT * FROM wp_postmeta WHERE meta_value LIKE '.$_POST['username'].' AND meta_value LIKE
I have this query: $query = SELECT *FROM wp_postmeta WHERE meta_key = '_isEvent' AND
i got this SQL query where post_title taken from $_GET $sql = SELECT ID
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I am trying to retrieve post_id, post_year, post_desc, post_title, post_date from one table and
I need to select statements where is fixed post id, group by user id
elseif(isset($_POST['submit'])) { // Look for their user $lookuser = mysql_query(SELECT * FROM `users` WHERE
Currently I'm running a MySQL query like this $query = SELECT t1.id AS 'post_id',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.