Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    183
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Fastest way to count values

    Hi

    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?


    thanks

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    183
    Thanks
    17
    Thanked 0 Times in 0 Posts
    thanks rep added


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •