List:General Discussion« Previous MessageNext Message »
From:Philip Mather Date:December 29 2006 3:08pm
Subject:Re: Count the number of specific rows
View as plain text  
Servers24,
> Well this question may seem funny...
No, a funny question would start something like "Why did the nun cross 
the road?". ;^)

> The problem is with counting a user's contribution in my site. Suppose 
> that
> each user that send an email will be stored in DB. Now I want to count
> number of times that a user has sent an email.
> I can simply use this :
> SELECT id FROM sent WHERE member_id= ...
> and the use count($result) to count the number, but I want a faster 
> way, if
Get MySQL to do the counting...
    "SELECT COUNT(*) FROM sent WHERE member_id = ...;"
...saying COUNT(*) is certainly no slower than saying COUNT(id) and the 
COUNT function is certainly faster than iterating over the result set 
using whatever language, also make sure you have indexed the member_id 
field as well.
    Alternatively you maybe able to incorporate a **|SQL_CALC_FOUND_ROWS 
|**into an existing query and then do a  **| |**|FOUND_ROWS()| to 
optimize things (see 
http://dev.mysql.com/doc/refman/4.1/en/information-functions.html) or 
failing that run a nightly query to compile the stats into a new table 
containing just member_id and emails_contributed fields?
    Those would be the standard options.

Regards,
    Phil
Thread
Count the number of specific rowsServers24 Network29 Dec
  • Re: Count the number of specific rowsDuncan Hill29 Dec
  • Re: Count the number of specific rowsPhilip Mather29 Dec
  • Re: Count the number of specific rowsPeter Brawley29 Dec
Re: Count the number of specific rowsPhilip Mather29 Dec