MySQL Count of related records
Posted: Fri Apr 20, 2007 9:58 am
Hi everyone
When doing a MySQL query, is it possible to also get the number of related records?
I have 2 tables related by an id field and when I loop through the records in the master table it would be really useful to also list the number of related records that are present in the secondary table.
One way I thought was to just loop through the secondary table and build an array manually of the info from the master table, counting the records as I go.
But I was wondering if there's a magical way to do it in MySQL?
Thanks
Ben
When doing a MySQL query, is it possible to also get the number of related records?
I have 2 tables related by an id field and when I loop through the records in the master table it would be really useful to also list the number of related records that are present in the secondary table.
One way I thought was to just loop through the secondary table and build an array manually of the info from the master table, counting the records as I go.
But I was wondering if there's a magical way to do it in MySQL?
Thanks
Ben