locked
Select Help RRS feed

  • Question

  • User1564938493 posted

    Hi

    Can anyone help me with this select query? I have a products table that contains a related productID in a comma seperated string like 1,2,8,7. The table structure is like this:

     

    ID |  Name | RelatedProducts

     

    I need to create a query that results in a list of the related products. I thought it would be something like this

     

    SELECT        products.name, products.ID, products.relatedProducts
    FROM            products LEFT OUTER JOIN
                             products AS products_1 ON products.relatedProducts = products_1.ID

    Can anyone help me with this?

     

    Thanx

     

    Leonaisse

     

     

     

    Thursday, September 12, 2013 7:08 PM

Answers

  • User-1716253493 posted

    Try like this

    SELECT products.name, products.ID, products.relatedProducts
    FROM products LEFT OUTER JOIN
    products AS products_1 ON products.relatedProducts Like '%' + CAST(products_1.ID as varchar) + '%'



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 12, 2013 8:52 PM