MySQL - 搜索 table1.field 的内容并将其替换为 table2.otherfield 的内容
我需要一个 MySQL 查询来执行以下操作:
我希望它引用teams.id,而不是球员表第三列中的 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
:团队表将保持不变。如果我能澄清任何事情,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)