I'm guessing there's a simple solution there somewhere, but it's driving me mad trying to get it to work. I want to perform two SUM()
queries on the same table but they both have different WHERE
clauses.
The table is used for a user voting system, so users vote on other users content. I want to be able to list the current user's activity (content/categories they've added), and combine it with details of how many other users have voted for the current users content.
Essentially i want to combine the two queries below from the same table.
SELECT category_id,
SUM(content_add) AS content_add_count,
SUM(category_add) AS category_add_count
FROM table1 WHERE user_id = '" . $user_id . "' GROUP BY category_id
SELECT SUM(normal_vote) AS agree_votes
FROM table1
WHERE issued_by_user != '" . $user_id . "'
AND user_id = '" . $user_id . "'
AND plus = '1'
GROUP BY category_id
I've tried putting the second query within another SUM()
in the first query above but that obviously can't be done in MySQL, but that's what I'd like to achieve if possible.