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.