sql - Update table based on a select from another -
i have select statement below use update quantity of products in table, tablex
. cannot seem figure out how match product number query productnumber tablex , add quantity found in statement existing quantity in tablex.
select p.productnumber, sod.quantity ,so.statecode salesorderdetail sod right join productassociation pa on sod.productid = pa.productid left join product p on pa.associatedproduct = p.productid left join salesorder on so.salesorderid = sod.salesorderid so.statecode = '3'
you can have update base on multiple tables, syntax like
update tablex set tablex.quantity = sod.quantity tablex join product p on tablex.productnumber = p.productnumber join... -- add rest of joins , conditions.
Comments
Post a Comment