我有 3 个 table :people
, country
, activity
**country**
id | people_id
1 3
2 1
3 2
**activity**
id | people_id
1 2
2 3
3 1
**people**
id | name
1 david
2 daniel
3 mark
正如您从上面看到的,country
和activity
使用 people_id
与人建立联系但是country
和activity
尚未相互连接。
我的问题是:如何连接这3个表?
感谢您的宝贵时间
最佳答案
两个表都通过 people_id
连接,您可以使用该连接..
select *
from people p
left join country c on p.id = c.people_id
left join activity a on p.id = a.people_id
如果您希望 people_id's
出现在所有三个表中,请将左联接
更改为内联接
关于mysql - 如何连接 3 个表,其中 2 个表与另外 1 个表相连,但彼此不相连,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45293678/