Counting User Post Count ?
I didn't think this was going to be so tricky. Basically I have two tables in my mysql database (user, comments). Each table has the users id. I simply just want to count how many posts/comments each user has and then place it in the user table, in a field called 'postnumber'. Can anyone guide me in the right direction on how I can achieve this ? I've searched the net but haven't found any useful information.
Thanks in Advance !!
Re: Counting User Post Count ?
This would get the user_name with post_count.
Code:
SELECT DISTINCT `user_name`, (SELECT count(*) FROM `tblComments` WHERE `tblComments`.`user_id`=`tblUsers`.`user_id`) AS `post_count` FROM `tblUsers`
Test it out. :wave: