0

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

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I spent ages trying to work this out... should have asked earlier :)
1
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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.