Home > Database > Mysql Tutorial > mysql update 多表实例

mysql update 多表实例

WBOY
Release: 2016-06-07 16:20:57
Original
963 people have browsed it

mysql update 多表实例讲解 我们先来看如下实例: 实例一: update tab1 set tab1.商品尺寸 = (select tab2.商品尺寸 from tab2 where tab2.商品颜色 = tab1.商品颜色) where tabl1.商品颜色 in (select tab2.商品颜色 from tab2) 继续如下实例: UPDATE CMS

   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

  等同于

  UPDATE Track,MV SET Track.is_show=MV.is_show WHERE Track.trkid=MV.mvid and trkid

  实例四:

  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

        :更多精彩文章请关注三联编程教程栏目。

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