You've more or less bracketed the solution, although a JOIN is not necessary.
Let's restate your first attempt in pseudocode:
Code:
UPDATE tbl_one
SET tbl_one.price = <the minimum price from tbl_two for this tbl_one.stockcode>
Now, to get the value of the expression in brackets for a given stockcode:
Code:
SELECT MIN(price) FROM tbl_two WHERE stockcode = <somevalue>
Now, we combine them. The mechanism we use to combine them is a correlated subquery, and the <somevalue> will be the stockcode in tbl_one that is being updated at the moment:
Code:
UPDATE tbl_one
SET tbl_one.price = (SELECT MIN(tbl_two.price) FROM tbl_two WHERE tbl_two.stockcode = tbl_one.stockcode);
You need to be careful about NULL here; if tbl_one has a stockcode which is not in tbl_two, the subquery will return NULL and that will update the tbl_one.price. Be sure that's what you want
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com