我有 6 个表,我将执行一条 sql 语句:
1)participant
***********
+id_participant
+id_poste
+name
+email
2) profile_formaion
****************
+id_poste
+id_formation
3) formation
*********
+id_formation
+lable
4) poste
*********
+id_poste
+label
5) session
*********
+id_session
+id_formaion
+lable
6) session_composition
*********
+id_session
+id_participant
EXAMPLE:
数据:参与者
1 | 2 | user1 | user1@mail.com
2 | 3 | user2 | user2@mail.com
数据:profile_formation
2 | 3
2 | 4
数据:编队
1 |formation1
2 |formation2
3 |formation3
4 |formation4
数据:邮政
1 |Poste1
2 |Poste2
3 |Poste3
数据:会话
1 |1 /* id_session 1 to id_formation 1 and id_formation=1 is formation1 */
数据:session_composition
1 |2 /* id_session 1 to id_participant 2 */
我在尝试:
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
如何使用 sql statement(join) 获取结果:
数据:结果
1 | 2 | user1 | user1@mail.com | poste2|formation3
1 | 2 | user1 | user1@mail.com | poste2|formation4
2 | 3 | user2 | user2@mail.com | poste3|formation1 // How can we join to get it.