0

I want to select the amount of forum posts compared to a list of users. So it will look like this:
USERID --- FORUMPOSTS
3647 - 2
7467 - 14
2673 - 39
3224 - 5
... and so on

Now I'm asking if it would be faster to count the forum post via COUNT(*) or looping through the userlist before and creating a new query for each user to count his/her forum posts via mysql_num_rows.

2 Answers 2

1

You can let SQL do the grouping and counting

select userid, count(*) as forumposts
from your_table
group by userid
Sign up to request clarification or add additional context in comments.

Comments

0

Now I'm asking if it would be faster to count the forum post via COUNT(*) or looping through the userlist before and creating a new query for each user to count his/her forum posts via mysql_num_rows.

It'll be faster to do the former, "count the forum post via COUNT(*)". You can group the results as follows:

SELECT userid, COUNT(*) FROM my_table GROUP BY userid

It'll be even faster still if your table has an index on the userid column.

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.