View Full Version : Fastest way to count values

07-21-2007, 10:43 AM

I have to count the amount of occurrences in a table of roughly 700,000 records and growing. I need to count how many times the email admin@website.com (for example) what is the fastest way to do this and will put as less stress on the servers as possible? I know about mysql COUNT and mysql_num_rows im not quite to sure how to use it so if COUNT is the fastest how do i use it with php?


07-21-2007, 11:28 AM
SELECT count(email) FROM table_name WHERE email='admin@website.com';

then use mysql_result from php, and create an index on the email field of the table. Loading all the records from the database, and then counting will almost certainly be slower, and 700,000 rows is well within mysql's comfort-zone.

07-21-2007, 11:37 AM
thanks rep added