/* to sum quantity of product from two stores into one */ /* 1,2 : are ids of stores to sum their products*/ /* 6 : is the id of new store*/ INSERT INTO storedetail ( `productid`, `storeid`, `productquantity`, `userid`, `storedetaildate`, `unittype` ) SELECT `productid`, 6, sum(`productquantity`), `userid`, `storedetaildate`, `unittype` FROM storedetail WHERE `storeid` in (1,2) group by `productid`;