It may be better to split the ON and WHERE conditions, even if the result is the same for INNER JOINs. Makes it clearer what links the two tables.
SELECT sum(cal2.somecolumn)
FROM consumer_action_log as cal1
JOIN consumer_action_log as cal2
ON cal1.COMMUNICATIONS_ID=cal2.COMMUNICATIONS_ID
WHERE cal1.COMM_TYPE_ID=4
- Find cal1 records where
COMM_TYPE_ID=4
- Join to cal2 (self join) where the COMMUNICATIONS_ID is equal to cal1
- Sum up some column from cal2
If the filter on COMMS_TYPE_ID=4
results in multiple cal1.COMMUNICATIONS_ID
s, then you will want to GROUP BY
COMMUNICATIONS_ID (doesn't matter from cal1 or cal2 - they are the same)
SELECT cal2.COMMUNICATIONS_ID, sum(cal2.somecolumn)
FROM consumer_action_log as cal1
JOIN consumer_action_log as cal2
ON cal1.COMMUNICATIONS_ID=cal2.COMMUNICATIONS_ID
WHERE cal1.COMM_TYPE_ID=4
GROUP BY cal2.COMMUNICATIONS_ID