Table structure:
activities id, name, tagId
activitiesTags id, title
activitiesReactions id, activityId, message
The query now:
SELECT A.id as activityId, A.name, A.tagId, T.id, T.title, COUNT(R.id)
FROM activities A
LEFT JOIN activitiesTags T
ON A.tagId = T.id
LEFT JOIN activitiesReactions R
ON R.activityId = A.id
GROUP BY A.id
ORDER BY A.id DESC
LIMIT ?
The problem is that I’m getting a reactionCount, but it is far from true, It seems that when an activity has an reaction, it times (*) the amount of actual reactions by two.
Does anyone know where the problem might be? Maybe the ORDER BY after GROUP BY?
Thanks
@knittl
Some modification to your query:
group_concatwill display all tags with delimiter (“,”). your query will display only the first one.