Jump to content

[SOLVED] One to Many relationship maybe many to many?


mjcoco

Recommended Posts

Ok im having trouble figuring this out.  Here is my problem, say you have a table of Professors and a table of Courses

 

Courses ex.  COSC CPSC MATH HIST

Professor ex. JOHN HARRY DAVE JIM

 

JOHN can teach COSC and CPSC

HARRY may only teach math

 

etc... you get the point.  Im having trouble with the logic.  Im trying to figure out without having to make a column for every course ( COSC CPSC ) to be able to link Professors to many courses as in the JOHN example.

 

Right now i have it to where they can only be associated with 1 course.  For example 1 = COSC

cour_id    prof
  1        JOHN

 

But what im looking to do is for JOHN to be associated with COSC AND CPSC

Hi,

 

firstly I recommend you reading MySQL sticky topics or just simple SQL tutorials. Your problem is realy basic stuff...

 

If one course may be teached by many professors and one professor may teach many courses use this structure:

 

Professors table:
| id | ProfessorName |
|  1 |     Profesor1 |
|  2 |     Profesor2 |

Courses table:
| id | CourseName |
|  1 |    Course1 |
|  2 |    Course2 |

ProfessorsCourses table:
| professor_id | course_id |
|            1 |         1 | 
|            1 |         2 | 

Professor1 is associated with Course1 and Course2.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.