mysql update 多表实例
mysql update 多表实例
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_未知')
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
实例四:
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'
注:更多精彩文章请关注三联编程教程栏目。