How would I get the SUM of the mutual field here?
SELECT first_user_id, mutual
FROM userprofile_usercontact
UNION ALL
SELECT second_user_id, mutual
FROM userprofile_usercontact
GROUP BY first_user_id
In other words I want to get SUM(mutual) for (first_user_id + second_user_id) where mutual = 1.
The question in the comment asks:
Using a filter condition, as usual:
The optimizer might well push the condition down into the UNION queries, so it would execute as if the query was written:
The net result is, of course, the same.