我想显示学生毕业的学校。我有一张学校名称表和一张学生资料表。这是我的代码:
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
问候,