作者:mobiledu2502861593 | 来源:互联网 | 2017-05-12 16:11
bitsCN.com
在sql server中,我们可是使用以下update语句对表进行更新:
update a set a.xx= (select yy from b) where a.id = b.id ;
但是在mysql中,不能直接使用set select的结果,必须使用inner join:
update a inner join (select yy from b) c on a.id =b.id set a.xx = c.yy
示例代码:
多表连接更新
UPDATE spgl_goods a INNER JOIN(SELECT g.`ID` AS idFROM rkgl_goods_repertory gr,rkgl_repertory r,spgl_goods gWHERE 1=1AND gr.`REPERTORY_ID`=r.`ID`AND gr.`GOODS_ID`=g.`ID`AND g.`IS_DELETE`=FALSEAND r.`USER_ID`=36GROUP BY gr.`GOODS_ID`) b ON a.`ID`=b.id SET a.`IS_DELETE`=TRUE;
bitsCN.com