开发者

update field from another select query

i am stuck with a simple query if someone can help me on on the same. i want to update one field with query from another table the table structure is as follows:- table stockmain - fields - itemcode, avgcost table sales - fields - itemid, saleprice, costprice(this field is to be generated with query from stockmain table(avgcost field) the query is follows:-

$qry = "UPDATE sales SET costprice = SELECT avgcost FROM st开发者_Python百科ockmain WHERE itemcode = 'sales.itemid' ";


You can join these two tables to get one data set, and then copy data from one field to another, e.g. -

UPDATE sales sl
  JOIN stockmain stm
    ON stm.itemcode = sl.itemid
SET sl.costprice = stm.avgcost;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜