SQL连接并重复结果?

时间:2012-12-04 09:57:16

标签: mysql sql

我有3张桌子:

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

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

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

EXAMPLE:

DATA:参与者

1 | 2 | user1 | user1@mail.com

DATA:profile_formation

2 | 3
2 | 4

DATA:形成

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

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

DATA:结果

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

由于

3 个答案:

答案 0 :(得分: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

答案 1 :(得分: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

答案 2 :(得分:1)

SELECT p。id_participant,p。id_poste,p。name,p。email,f。lable FROM参与者p加入profile_formaion pf on p.id_poste = pf.id_poste在pf.id_formation = f.id_formation上加入阵型f