I have a MySQL table comment with the following fields:
loginid submissionid points
I have a MySQL table called submission with the following fields:
loginid submissionid
For a given submissionid, the loginid in the two tables represent different things and therefore do nor correspond.
I would like a join to sum up points by loginid. However, not by the loginid in comment, but rather the loginid in submission. The connection between the two tables is made via the submissionid
I can’t get this to work. Below is what I have so far. I’m trying to get this desired sum for each loginid pulled from another, third table, which is what the l.loginid represents.
How can I do this?
LEFT JOIN (
SELECT C2.submissionid, C2.loginid SUM(points) AS total
FROM comment C2
INNER JOIN submission S2
ON S2.submissionid = C2.submissionid
GROUP BY C2.submissionid
) cscs ON cscs.loginid = l.loginid
This will give you a points sum for each loginid in the submission table.