Britta,

I don't think PHP or mySQL would help your situation since the problem is
strictly database related and mySQL does not support nested queries which is
helpful at times.

 
> TO ADD A NEW PRODUCT from "new" to "Products2" if not already listed in
> "Products2":
> INSERT INTO Products2 (ProductID, Product, UnitPrice)
> SELECT ProductID, Product, UnitPrice FROM new
> WHERE new.Product <>Products2.Product
> (but this creates huge amounts of duplicates.  I need the product just =
> to be
> added once.)

Try this:

INSERT INTO Products2 (ProductID, Product, UnitPrice)
SELECT ProductID, Product, UnitPrice FROM new
WHERE ProductID NOT IN (SELECT ProductID FROM Products2)

This will get all all the products NOT IN the Products2 table.

> Update price of existing product:
> UPDATE Products2 (UnitPrice)
> SET UnitPrice=3D(SELECT UnitPrice FROM new)
> WHERE new.Product=3DProducts2.Product
> (I want to update those records in Products2 that have a different =
> UnitPrice

"SELECT UnitPrice FROM new" will get ALL the prices from that table and
that's not what you want. You only want to return the record for that
specific ProductID (WHERE New.ProductID = Products2.ProductID).

UPDATE Products2 
SET UnitPrice= (SELECT UnitPrice FROM new WHERE New.ProductID =
Products2.ProductID)
WHERE new.ProductID = Products2.ProductID AND New.Price <> Products2.Price


Xing

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to