Relationships

Many to many

students:
id | first  | last
=====================
1  | John   | Lee
2  | Jane   | Wilson
3  | Daniel | Gomez
 
classes:
id | name    | teacher_id
==========================
1  | Biology | 2
2  | Physics | 4
3  | English | 77
 
student_classes
s_id | c_id
======================
  1  |  2   # John is taking Physics 
  1  |  3   # John is taking English
  2  |  2   # Jane is taking Physics
  3  |  1   # Daniel is taking Biology

From gist.github

Foreign keys

https://dev.mysql.com/doc/workbench/en/wb-foreign-key-relationships.html

MyWiki: SQL/Relationships (last edited 2018-06-01 22:08:34 by risca)