2

我有 3 张桌子:

1)participant
  ***********
  +id_participant
  +id_poste
  +name
  +email

2) profile_formaion
  ****************
  +id_poste
  +id_formation

3) formation
  *********
  +id_formation
  +lable

EXAMPLE:

数据:参与者

1 | 2 | user1 | user1@mail.com

数据:profile_formation

2 | 3
2 | 4

数据:编队

1 |lable1
2 |lable2
3 |lable3
4 |lable4

任何人都可以帮助我如何使用 sql statement(join) 来获得结果:

数据:结果

1 | 2 | user1 | user1@mail.com | label3
1 | 2 | user1 | user1@mail.com | label4

谢谢

4

3 回答 3

5
SELECT 
    participant.id_participant,
    participant.id_poste,
    participant.name,
    participant.email,
    formation.lable 
FROM participant
INNER JOIN profile_formaion ON
    profile_formaion.id_poste = participant.id_poste 
INNER JOIN formation ON
    formation.id_formation = profile_formaion.id_formation
于 2012-12-04T10:00:48.863 回答
1

选择页。id_participant,页。id_poste,页。name,页。email,F。lableFROM 参与者 p 加入 profile_formaion pf on p.id_poste = pf.id_poste 加入形成 f on pf.id_formation = f.id_formation

于 2012-12-04T10:06:05.893 回答
1

这应该这样做

select p.*, f.lable
from participant p
join profile_formaion pf on pf.id_poste = p.id_poste
join formation f on f.id_formation = pf.id_formation
于 2012-12-04T10:02:36.457 回答