mysql update select

在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 id
FROM 
rkgl_goods_repertory gr,
rkgl_repertory r,
spgl_goods g
WHERE 1=1
AND gr.`REPERTORY_ID`=r.`ID`
AND gr.`GOODS_ID`=g.`ID`
AND g.`IS_DELETE`=FALSE
AND r.`USER_ID`=36
GROUP BY gr.`GOODS_ID`
) b ON a.`ID`=b.id 
SET a.`IS_DELETE`=TRUE;



mysql update select

上一篇:PLSQL Developer并不支持Oracle 64位客户端连接!!!!(注意了)


下一篇:windows 快速删除海量小文件的方法