• SELECT p.ProductID,

    CASE WHEN R1.FirstProductID IS NULL and R2.SecondProductID IS NULL then 'Not Linked' ELSE 'Linked' END Relation

    FROM @product p

    LEFT JOIN @ProductRelation R1 ON R1.FirstProductID = p.ProductID

    LEFT JOIN @ProductRelation R2 ON R2.SecondProductID= p.ProductID

    ORDER BY p.ProductID

    OR

    SELECT p.ProductID,

    CASE WHEN R.FirstProductID IS NULL and R.SecondProductID IS NULL then 'Not Linked' ELSE 'Linked' END Relation

    FROM @ProductRelation R

    RIGHT JOIN @product p ON p.ProductID = R.FirstProductID OR p.ProductID = R.SecondProductID

    ORDER BY p.ProductID

    _____________
    Code for TallyGenerator