Mysql查询从3个IDS中获取3个名称

时间:2015-06-12 09:35:14

标签: php mysql sql database

我有这个设置:

表成员

datetime.strptime (time , "%Y-%m-%d %H:%M:%S.%f %Z")

表团队

id_member name  
---------------

现在我想在html表格中显示所有团队的这些字段: id_team,leader name,member1的name,member2的名称

尝试了多个选项的多个查询,但是当一个成员位于多个团队中时出现问题,显示了错误的结果(所有组合)

我想要的例子: http://oi58.tinypic.com/ao9oxi.jpg

1 个答案:

答案 0 :(得分:0)

尝试使用如下连接查询

select TEAM.id_team, LEADER.name, MEMBER1.name, MEMBER2.name 
from teams as TEAM 
join members as LEADER on(LEADER.id_member=TEAM.id_leader) 
join members as MEMBER1 on(MEMBER1.id_member=TEAM.id_member1) 
join members as MEMBER2 on(MEMBER2.id_member=TEAM.id_member2)