我有这个设置:

表成员

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


表队

id_team   id_leader   id_member1   id_member2
---------------------------------------------


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

尝试了多个选择的多个查询,但是当一个成员属于一个团队以上时,存在问题,显示错误的结果(所有组合)

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

最佳答案

尝试如下使用联接查询

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)

07-28 13:55