There is a table of goods. id product There is such a table. Each product may have its own set. What is the best way to make such a connection? What I thought to do. Create a table. id, tovar1, tovar2, tovar3, tovar4, tovar5. And simply register the id of the related products in tovar1, tovar2, and so on. But something that I don’t really like such a scheme, there may not always be 5 sets, maybe 3 and 4. What should I do?

  • Can a product have only one set? - Dmitriy Simushev
  • no, there can be 2 and 3. For example, a ring can have earrings and a chain - duddeniska
  • read about many-to-many connections, and create yourself a database. - teran
  • @duddeniska, then I agree with the previous comment: many-to-many help you - Dmitriy Simushev

1 answer 1

It makes sense to create a set table, in which there will be only its ID and, for example, its name ( Sets(id, name) ). And also create a table of relationships ("many-to-many") of goods and sets, in which there will be fields product_id and set_id (and, if desired, id ).
In this case, you can add to the kits any quantity of goods.

  • that's great , they helped - duddeniska