我需要一个MySQL查询,它将执行以下操作:
我希望它引用teams.id
而不是播放器表第3列中的alpha团队名称。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
因此,在搜索和替换更新后,播放器表格将如下所示:
id player_name team
------------------------------------------
1 Sue Smith 3
2 Mike Olson 1
3 Tim Hood 3
4 Chris Row 2
5 Fred Ware 1
球队表将保持不变。如果我能澄清任何事情,请告诉我。
答案 0 :(得分:3)
update players, teams set players.team = teams.id where players.team = teams.name