Jump to content


Photo

Combining values from two separate tables


  • Please log in to reply
1 reply to this topic

#1 benjam

benjam
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts
  • LocationSalt Lake City, UT

Posted 13 October 2006 - 08:24 PM

I have a chess script and I would like to add the total wins, draws, and losses collected in one instance (table) to the wins, draws, and losses collected in another instance (table).

For instance:

table 1 is like:
player
p_id
p_username
p_wins
p_draws
P_losses

and table 2 is like:
wc2_player
p_id
p_username
p_wins
P_draws
p_losses

I would like to add the wins from `player` into `wc2_player`, but only if the value for p_username is the same.

Can I do this in one query?  Both tables are in the same DB.
Windows 7
MySQL: 5.1.36-community
PHP: 5.3.2 VC9
Apache 2.2 (apachelounge VC9)

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 October 2006 - 10:39 PM

Try the following (UNTESTED, so back up your DB!)
UPDATE wc2_player INNER JOIN player USING p_username 
SET wc2_player.p_wins += player.p_wins

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users