locked
lost, need help with database RRS feed

  • Question

  • User1340490396 posted

    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?

    Monday, February 7, 2011 9:13 AM

Answers

  • User-1203469223 posted

    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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 7, 2011 10:37 AM

All replies

  • User-1203469223 posted

    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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 7, 2011 10:37 AM
  • User2004711764 posted

    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?


    Morzel

    Monday, February 7, 2011 10:38 AM
  • User1340490396 posted

    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

    Monday, February 7, 2011 11:30 AM