mysql update 多表实例。
先来看几个例子:
实例一:
复制代码 代码示例:
update tab1 set tab1.商品尺寸 = (select tab2.商品尺寸 from tab2 where tab2.商品颜色 = tab1.商品颜色) where tabl1.商品颜色 in (select tab2.商品颜色 from tab2)
实例:
复制代码 代码示例:
UPDATE
cms_Document A,CMS_Template B SET A.RuleType2=B.RuleType WHERE A.TemplateID = B.TemplateID
替代的方法可以采用:
复制代码 代码示例:
update customers a -- 使用别名 set city_name=nvl((select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id),a.city_name)
或者
set city_name=nvl((select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id),'未知')
MySQL多表更新实例三:
复制代码 代码示例:
update contact c, contactdroit cd set c.user_name = '$username', c.nom = '$lastname', c.prenom = '$firstname', c.passcode = '$password', cd.droit_id = '$droitid' where c.contact_id = '$id' and c.contact_id = cd.contact_id;
mysql关联多表进行update更新操作:
复制代码 代码示例:
UPDATE Track INNER JOIN MV ON Track.trkid=MV.mvid SET Track.is_show=MV.is_show WHERE trkid<6
等同于:
复制代码 代码示例:
UPDATE Track,MV SET Track.is_show=MV.is_show WHERE Track.trkid=MV.mvid and trkid<6
MySQL多表更新,例四:
复制代码 代码示例:
UPDATE product p INNER JOIN productPrice pp ON p.productId = pp.productId SET pp.price = pp.price * 0.8,p.dateUpdate = CURDATE() WHERE p.dateCreated < '2004-01-01'