Adding together multiple numbers that correspond to a certain name

Hey guys, currently I understand just a bit of adding numbers from mysql together for a table, but I’m looking to add together only numbers that correlate with a certain persons name together to show in a table on my site.

My mysql has (Name, and points, as well as a timestamp)

I am looking to make it so, if “Joe Bob” was given 10 points two different times, and “Bob Joe” was given 10 points, it would show up as 20 on the table, while also showing “Bob Joe” as having his own 10 points as well.

I understand the easiest way to do this is to use the update function and just update each person when they are given points, but I am working on making it so after a set amount of time (for example 2 weeks) the points would not be shown anymore, that is why I am using the timestamp.

Your table holding the points records should use the user_id, not the user name. This will result in the least amount of storage, the fastest queries, and allow the user’s name to be edited without requiring all the records to be updated to match.

You would then use GROUP BY user_id to consolidate rows for the same user id, and use SUM(points) to get the total of the points per user. To only include records with a certain ‘age’, you would add a WHERE clause to the query to match the timestamp column values that you want. To only include specific users, the WHERE clause would match the user ids that you want.


Currently I am working with steam users. Do you think it would work if I used steam’s for user_id, so the id’s would be different for each user, but the same for the same user if used more than once.

I’m a bit confused on the sum portion of this. What is the best way to call the sum of points, because as I am looking at it wouldn’t sum basically add up all of the points in the table?

OK, you were indeed right. just had a bit of trouble getting the stuff to fit all correctly. Thanks man

Sponsor our Newsletter | Privacy Policy | Terms of Service