-1

According to a simple scenario ER diagram as follows.

enter image description here

Based on that, I developed a database mapping as follows.

enter image description here

In there, orange color columns shows the primary key of the tables and yellow color columns shows foreign key of the tables. Is this mapping correct? Now my problem is I need to retrieve students data who learned from some teacher, which means need to retrieve some teacher's sudents who learned from his/her.

2
  • Show us what you have tried till now?
    – PSK
    Feb 11, 2019 at 9:33
  • @PSK sir I'm new to databases, I don't have an idea to write join query to do this.please help me
    – Rooter
    Feb 11, 2019 at 9:34

1 Answer 1

1

You need to learn about how to join tables using different types of available JOINs.

For your scenario , try like following, it will give you Student and the Teacher mapping.

select s.*
tbl_student s
inner join tbl_Course_Subjects tcs on s.Course_Id= tcs.Course_Id
inner join tbl_Subjects_Teacher tst on tst.SubjectId=tcs.Subject_Id
inner join tbl_Teacher t on t.Teacher_Id=tst.Teacher_Id
where t.Teacher_Id = @SomeTeacherId
2
  • Thank you very much sir :) can you please explain is this mapping is correct? Should I need to normalize this?
    – Rooter
    Feb 11, 2019 at 9:51
  • As per the ERD, the design looks fine to me.
    – PSK
    Feb 11, 2019 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.