database – An example of a many-to-many relationship


Hello! I can't understand the many-to-many relationship. What does she mean? Please give an example when this connection needs to be established. Better even give an example from life, please, when such a connection is made.


"One-to-many" is a type of table relationship, when one record of the main table can be associated with several records of the subordinate table. This is the most common type of relationship between tables. Well, for example, if you create a telephone directory, then you need to take into account that one person can have several phones (2 mobile, 1 home and 1 business). Or another example: a student (records about students are stored in the main table) studies at a university – he studies several subjects (records about subjects are stored in a subordinate table), for which he takes exams and tests.

And the relationship "many-to-many" occurs in cases when one record of one table can correspond to several records of another table and vice versa: when one record of the second table can correspond to several records of the first table. You should get rid of this type of relationship and bring it to a one-to-many form. An example of this type of communication: we have 2 tables "Products" and "Customers", each client can purchase several products, in turn, each product (by name) can be purchased (or ordered) by several customers. Another example (for the university): let there be 2 tables "Teacher" and "Student", each teacher can teach several students, at the same time, each student can learn from several teachers.

Scroll to Top