Counting multiple entries in a MySQL database?

Posted by Aaron on Stack Overflow See other posts from Stack Overflow or by Aaron
Published on 2009-03-06T20:30:20Z Indexed on 2010/12/21 12:54 UTC
Read the original article Hit count: 312

Filed under:
|
|

Hi all,

I'm trying to count multiple entries in a MySQL database, I know how to use COUNT(), but the exact syntax I want to get the results I need eludes me.

The problem: Table structure: ID, CODE, AUTHOR, COUNTRY, TIMESTAMP.

Code, Author and Country overlap many times in the table. I am trying to discover if there is one simple query that can be ran to return (using WHERE clause on COUNTRY) the author field, the code field, and then a final field that counts the number of times the CODE was present in the query result.

So, theoretically I could end up with an array like:

array('author', 'code', 'codeAppearsNTimes');

Authors also have varying codes associated with them, so I don't want the results merged. I suppose the end result would be: 'This author is associated with this code this many times'.

Is this possible with MySQL?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql