MySQL Forums
Forum List  »  Newbie

Re: Simple many to many query...
Posted by: Phillip Ward
Date: November 28, 2013 06:50AM

Quote

... two simple tables in a many-to-many relationship ...
That might be better represented as three tables - your two "simple" ones plus a third that describes the linkages between the two.

   select * from Classes ; 

   +----+------------------+ 
   | ID | Title            | 
   +----+------------------+ 
   |  1 | Business Studies | 
   |  2 | Chemistry        | 
   |  3 | History          | 
   +----+------------------+ 

   select * from Students ; 

   +----+----------+------------+ 
   | ID | Forename | Surname    | 
   +----+----------+------------+ 
   | 77 | Pebbles  | Flintstone | 
   | 88 | Bam Bam  | Rubble     | 
   +----+----------+------------+ 

select Class_ID, Student_ID from Enrolments ; 

   +----------+------------+ 
   | Class_ID | Student_ID | 
   +----------+------------+ 
   |        2 |         77 | 
   |        1 |         88 | 
   |        2 |         88 | 
   +----------+------------+

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
Re: Simple many to many query...
November 28, 2013 06:50AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.