Last post Feb 07, 2011 11:30 AM by lekso
Feb 07, 2011 09:13 AM|lekso|LINK
Hi. This must be a simple question, but I don't know how to implement this in a best way. In an online shop database I've got a table with all products and when displaying them online I'd like to advertise some other related products from the same table.
In ideal world there would probably be only one more table RecommendedProducts with two fields "ProductID" and "ProductID2" both fields of which are linked to the Products table, but this design won't work. Could anyone please help?
Feb 07, 2011 10:37 AM|tompy_nation|LINK
Why is that not working?
Just create a new Table: RelatedProducts
Create 2 columns in it: ProductID & RelatedProductID
Set your primary key to a combination of those fieldsd and you are ready...
To get a list of related products:
Select * FROM RelatedProducts WHERE ProductID = yourProductID
Feb 07, 2011 10:38 AM|Morzel|LINK
If your relationship looks like a tree, you can put it into table Products (Column name parent ID) and in that case, your child elements will be the related records.
If a product can be related to many products, you have to put it into a new table RecommendedProducts.
And why this design won't work at your project?
Feb 07, 2011 11:30 AM|lekso|LINK
Hi, I checked again anf found the reason for error message, the problem was with wrong data entered in the DB and now it works as intended. Thank you both for help. Alex