SELECT statement problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samvb
    New Member
    • Oct 2006
    • 228

    SELECT statement problem

    Hi,

    I have this 3 tables:
    Code:
    tblProducts: productid,producntname
    tblIngredient:ingredientid,ingredientname
    tblProductsIngredients:autoid,productcode,ingredientcode,amountneeded
    Products are made by certain amount of ingredients. I can add new products and all but am having problem wit updating product. During editing product, I want to list ingreidents that are not already added to the product along with ingredients (and their amounts) that are already specified for the product. I tried this code but it only returns already specified products while sometimes adds only one new ingredient to the list to be added:

    Code:
    $strsql="SELECT * FROM viewexistingandnewingredientswithproducts WHERE productcode=$id OR productcode IS NULL";
    
    }
    where viewexistingand newingredientsw ithproducts is defined as

    Code:
    select * from tblingredients,tblProductsIngredients where ingredientid=ingredientcode
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What you've done is basically an inner join. It will never show ingredients that aren't in the product. What you want to do it outer join the tables.

    Comment

    Working...