So, I’ve got a mysql query that looks like this:
SELECT rewards.name, redemptions.points, redemptions.value
FROM rewards
INNER JOIN redemptions ON rewards.id = redemptions.reward_id;
The problem is that it spits out a table like this:
-----------------------------
| Reward 1 | 500 | 30 |
-----------------------------
| Reward 1 | 500 | 30 |
-----------------------------
| Reward 1 | 500 | 30 |
-----------------------------
| Reward 2 | 100 | 10 |
-----------------------------
| Reward 2 | 100 | 10 |
-----------------------------
| Reward 3 | 250 | 20 |
-----------------------------
and so on. Ideally, what I would actually like it to do is to only list each one once, but sum certain columns. So for example, it would look something like this:
-----------------------------
| Reward 1 | 500 | 90 |
-----------------------------
| Reward 2 | 100 | 20 |
-----------------------------
| Reward 3 | 250 | 20 |
-----------------------------
Where it is summing the third column, but listing the first two columns just once. I thought maybe a union would do it because I know it ignores duplicates, but I don’t think it works while using unions as well.
Use
SUM, and remember to addGROUP BY: