So i have a mysql query that queries a table "contacts" each contact then has purchases. Purchases are in a related table. I want to display each contacts name with the number of purchases they have made to the right like this:
Adam(1)
Mike(8)
Steve(3)
My current sql looks like this:
SELECT * FROM contacts ORDER BY contacts.name ASC"
and my current table looks like this:
Adam
Mike
Steve
In order to pull the count of the related (purchases) table into the current table i know i have to join the "purchases" table some how and then use the GROUP BY and count() function but i am not sure how to construct this sql statement. Can someone help me.
Again all i am trying to do is list a table (contacts) and count it's related records (purchases) and have it look like this:
Adam(1)
Mike(8)
Steve(3)
Thank you so much for any help.