Reputation: 293
I have a working generated SQL query, however I can't work out how I can count it!
The GROUP BY
function stops a normal COUNT(*)
from working.. hope someone can help.
SELECT wposts.* FROM wp_posts wposts, wp_postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'phone'
AND wpostmeta.meta_value = '1542'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'tips' || wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'phone'
AND wpostmeta.meta_value = '1541'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'tips' || ........
GROUP BY wposts.post_content
ORDER BY wposts.post_title ASC
Thanks
Upvotes: 0
Views: 91
Reputation: 739
SELECT COUNT(DISTINCT wposts.post_content)
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'phone'
AND wpostmeta.meta_value = '1542'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'tips' || wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'phone'
AND wpostmeta.meta_value = '1541'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'tips' || ........
ORDER BY wposts.post_title ASC
Upvotes: 1
Reputation: 52372
Remove the GROUP BY
and change the SELECT
to only COUNT(DISTINCT wposts.post_content)
to get the number of rows this query would have returned.
Upvotes: 4