0

I've got 2 tables setup like so:

> events
-----------------------------------
id | event | eventHandle | points
-----------------------------------
1 | Event One | eventOne | 5
2 | Event Two | eventTwo | 10


> entries
-----------------------------------
id | user | eventHandle
-----------------------------------
1 | 1 | eventOne
2 | 1 | eventTwo
3 | 1 | eventTwo
5 | 5 | eventOne

And what I need to do is get the amount of 'points' each user has gained related to each event.

For example, user 1 has got 25 points and user 5 has 5 points.

What I can't figure out is how get the points, based one the eventHandle and sum them together.

I managed to select the different data from different tables, and do a basic sum with a different query, but not combined. Mind boggling.

Any help is mighty appreciated!

2
  • 1
    You need a join Commented Jul 5, 2016 at 15:55
  • 1
    join, group by and sum should do it. select en.user, sum(points) from events ev inner join entries en on ev.eventHandle = en.eventHandle group by en.user Commented Jul 5, 2016 at 15:58

1 Answer 1

1

All you need to do is a simple inner join between the 2 tables on eventHandle fields and sum points by users:

select en.user, sum(ev.points)
from events ev
inner join entries en on ev.eventHandle=en.eventHandle
group by en.user
Sign up to request clarification or add additional context in comments.

1 Comment

Amazing. That worked perfect and didn't seem as complicated as I thought it would be. I was obviously over engineering it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.