Home > Database > Mysql Tutorial > body text

mysql实现两表关联更新_MySQL

WBOY
Release: 2016-06-01 13:26:56
Original
1805 people have browsed it

bitsCN.com

update的基本语法是update 表 set 字段 = 值 where 字段 = xxx

现有物料表materials(y_name,y_quantity), 产品表a(p_name,p_quantity),要将产品a所用的物料汇总到materials上

如果做关联网上给的一种写法不适用mysql

select a.p_quantity + m.y_quantity + b.p_quantity from materials m,pro_a a,pro_b b where a.p_name = m.y_name and b.p_name = m.y_name ;

应该是这么写:

update materials m left join pro_a a on m.y_name = a.p_name set m.y_quantity = a.p_quantity + m.y_quantity ;

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