Forum Moderators: coopster
I have a list of companies in one table with fields for address and contact and phone, etc.
Each of these companies can have an infinite number of products that they carry, and I'd like to create a second table that I can relate back to the first with this information. But it seems to me, each company would have to have its own table to list all the products. Am I thinking about this right?
How do I go about connecting these two sets of information. I'm thinking I need to join tables, but can't figure out how that works. As usualy, any and all help is appreciated.
I have a list of companies that I expect to continue growing (and grow quite large).
I have contact info (including address, email, phone, etc.) for each company.
And I have a list of products that each company carries. However, this list of products is continually growing as well, and is expected to be quite large for some of the companies. And, some of the products will be listed with multiple companies. With this being the case, I can't see how I can fit this product information into the same table as the contact info.
What I'm thinking is that I should have one table that lists all the companies with their contact info, and then each company breaks into it's own table to list all of the products it carries. Does this make sense? Is it feasible?
contacts
contact_id
contact_name
address
etc.
products
product_id
product_name
description
etc.
products_carried
contact_id
product_id
Populating the first two tables is fairly straightforward, enter your contacts and enter the products. The last table then would be "connecting" each contact with a list of the products they sell.
+------------+------------+
¦ Company_Id ¦ Product_Id ¦
+------------+------------+
¦ ____x_____ ¦ ____e____ ¦
+------------+------------+
¦ ____x_____ ¦ ____g____ ¦
+------------+------------+
¦ ____y_____ ¦ ____g____ ¦
+------------+------------+
¦ ____z_____ ¦ ____e____ ¦
+------------+------------+
¦ ____z_____ ¦ ____f____ ¦
+------------+------------+
¦ ____z_____ ¦ ____g____ ¦
+------------+------------+
So, there would be multiple entries for each company that carried multiple products. Just trying to make sure I understand the concept.
To prevent duplciates, create a multifield key across Product_id and Company_id.
BTW, the term for what we're up to here is a "Many-to-many relationship," in case you want to research the concept more thoroughly.