Firstly, your design is wrong. you don't need to have a reference from Subject to Departments because Department is accessible through Semester and the D_Id in Subject is redundant, IMHO.
Second, what is your criteria for retrieving subject?
Select Sub_Name
from Subjects as sbj
inner join Departments as dpt on sbj.D_Id = dpt.D_Id
inner join Semester as smt on sbj.sem_id = smt.sem_id
where (YOUR CRITERIA)
This is basically the general correlation among your tables, so you could specify the conditions and list of fields to be retrieved.
However it's best to rectify your design first and then access department through Semester :
inner join Departments as dpt on smt.D_Id = dpt.D_Id
thereby you're gonna use the dependency in semester rather than subjects!
p.s.
if the department in subject is different from the on in semester then your layout is good as it is, but if they're same thing then you can get rid of the latter
manpreet
Best Answer
2 years ago
I have three tables
DEPARTMENTS
,SEMESTER
andSUBJECTS
If user insert
department_name
inDEPARTMENTS
table andsemester
fromsemester
table then how to getsub_name
fromsubject