Home > Database > Mysql Tutorial > mysqlupdateselect_MySQL

mysqlupdateselect_MySQL

WBOY
Release: 2016-05-27 14:12:09
Original
1412 people have browsed it

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;
Copy after login
bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template