views:

40

answers:

1

I need a MySQL query that will do the following:

Instead of the alpha team names in the 3rd column of the players table, I want it to reference teams.id

table: players

id         player_name           team
------------------------------------------
1          Sue Smith         Silly Chimps
2          Mike Olson        Black Cats
3          Tim Hood          Silly Chimps
4          Chris Row         Grease Monkeys
5          Fred Ware         Black Cats


table: teams

id              name
-------------------------------
1              Black Cats
2              Grease Monkeys
3              Silly Chimps

So after the Search and Replace update, the players table will look like:

id         player_name           team
------------------------------------------
1          Sue Smith              3
2          Mike Olson             1
3          Tim Hood               3
4          Chris Row              2
5          Fred Ware              1

The teams table will remain untouched. Let me know if I can clarify anything.

+3  A: 
update players, teams set players.team = teams.id where players.team = teams.name
Trevor
Thanks tvor, worked perfectly!
k00k
No problem, glad to help :)
Trevor