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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.