gpt4 book ai didi

mysql - 如何在 MySQL 中连接 3 个表?

转载 作者:行者123 更新时间:2023-11-29 11:31:31 25 4
gpt4 key购买 nike

我有表A:姓名 ID |姓名 1 乔 约翰二书 3 雅各布 4 苹果 5 罗杰

表B:

SportID | SportName
1 Basketball
2 Soccer

表C:

ID | NameID | SportID

1 1 1
2 1 2
3 2 2
...

如何连接这些表以便获得可读的内容?

Joe | Basketball
Joe | Soccer
Jacob | Soccer

最佳答案

您应该将表连接在一起:

select a.name, b.sportname
from tablec c
join tablea a on c.nameid = a.nameid
join tableb b on c.sportid = b.sportid

关于mysql - 如何在 MySQL 中连接 3 个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37336742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com