学生が卒業した学校を表示したい。学校名の表と生徒のプロフィールの表があります。これが私のコードです:
school_db
shc_id shc_title
1 School A
2 School B
3 School C
4 School D
5 School E
学生データベース
stu_id stu_school1 stu_school2 stu_school3
1 1 2 2
2 1 2 4
3 2 2 4
だから私は書く:
select school_db.sch_title as school from school_db
inner join student_db on student_db.stu_school1=school_db.shc_id
inner join student_db on student_db.stu_school2=school_db.shc_id
inner join student_db on student_db.stu_school3=school_db.shc_id
where student_db.stu_id='1'
しかし、正しい結果を得ることができませんでした。この場合、適切な結合を使用する方法を提案してください。
結果は次のようになると思います。
stu_id stu_school1 stu_school2 stu_school3
1 School A School B School B
2 School A School B School D
3 School B School B School D
よろしく、