Merging results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mikitoq
Forum Newbie
Posts: 1
Joined: Fri Jul 21, 2006 9:05 am

Merging results

Post by mikitoq »

Hi,

I have three tables as follows..
comments
topics
scores

each have a user_id and a user_points field. I want to take the values for user_points from comments and topics for all users, add these together and populate the scores table.

e.g user_id of 1 has 3 topics + 4 comments so my query should now populate scores as follows
user_id = 1
user_points = 7

etc..

Can this be done in a single query and if so how do I go about doing it?

Thanks in advance!!

M
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Sounds like you could do it with an "insert..select" but I'd probably need to see your table structures as reported by MySQL first.
Post Reply