我有4张桌子:
- 学生(ID(PK),名称,subject_enrolled(FK)
- 教师(ID(PK),名称,subject_teaches(FK)
- 主题(subject_code(PK),SUBJECT_NAME)
- 合并(FIELDS尚未知晓)
醇>
通过使用MYSQL触发器,我想将数据插入学生表,它将自动获取教师表的名称,并根据注册的主题和主题教授将其放置到Combined
表。实现这一目标的最佳方法是什么?
答案 0 :(得分:0)
您可以使用以下查询来获取它,您不需要单独的表和触发器
SELECT ST.name as Student_name,T.name as Teacher_name ,S.subject as Subject ,S.subject_code as Subject_code from Student ST
inner join Subject S on S.subject_code=ST.subject_enrolled
inner join Teacher T on T.subject_teaches=S.subject_code
where ST.id=<your student id>