![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
i came accross requirement of multiple foreign keys in a table referencing the same primary key another table. i created the table relations using the relations editor in access. even though i could have multiple foreign keys to a table access did allow the referential integrity. my database structure is table1 - students table table 2 - subjects table table 3 - subjects opted by students in the table 3 totally there are 6 subject columns and a student can opt for variable number of subjects. table structure students ID -> primary key, FirstName, LastName, ........ subjects ID->primary key, subject student_subjects ID->primary key, StudentID->foreign key referencing students.ID, and sub1, sub2, .....sub6 all of which reference the primary key in subjects table. now if in the student_subjects table i have a record with data ID-1000, StudentID-100, sub1-1, sub2-2......sub6-6, how can i join table in SQL query to access the student_subjects table so that i can display the result as ID->studentID (name not required) but from sub1 to sub6 i should display the actual subject name that is in the subjects table ? for example : ID sub1 sub2 sub3 ........................ sub6 1000 telecom. cryptography networking ....................... cgi/perl Restructure table3 - something like this: |
#3
| |||
| |||
|
|
i came accross requirement of multiple foreign keys in a table referencing the same primary key another table. i created the table relations using the relations editor in access. even though i could have multiple foreign keys to a table access did allow the referential integrity. my database structure is table1 - students table table 2 - subjects table table 3 - subjects opted by students in the table 3 totally there are 6 subject columns and a student can opt for variable number of subjects. table structure students ID -> primary key, FirstName, LastName, ........ subjects ID->primary key, subject student_subjects ID->primary key, StudentID->foreign key referencing students.ID, and sub1, sub2, .....sub6 all of which reference the primary key in subjects table. now if in the student_subjects table i have a record with data ID-1000, StudentID-100, sub1-1, sub2-2......sub6-6, how can i join table in SQL query to access the student_subjects table so that i can display the result as ID->studentID (name not required) but from sub1 to sub6 i should display the actual subject name that is in the subjects table ? for example : ID sub1 sub2 sub3 ........................ sub6 1000 telecom. cryptography networking ....................... cgi/perl |
![]() |
| Thread Tools | |
| Display Modes | |
| |