Here is my table structure:
-- reputations
+----+-------------+---------+-------+------------+------------+
| id | post_id | user_id | score | reputation | d
Did you try adding the post id to the query?
I added count(r.post_id) as post_num
in your select
statement and it gave the expected results.
To remove duplicates, use distinct
. Do you want the count with respect to tag table? Try
COUNT(distinct pt.post_id) AS post_count
; or COUNT(distinct r.post_id) AS post_count