MySQL Update multiple table instance

Source: Internet
Author: User
Tags join mysql update

MySQL Update multi-table example explanation

Let's take a look at the following examples:

Example one:

Update TAB1 set TAB1. Product size = (select TAB2. Product size from TAB2 where tab2. Product color = tab1. Product color) where TABL1. Product color in (select TAB2. Product Colors From TAB2)

Continue with the following examples:

UPDATE cms_document a,cms_template B SET a.ruletype2=b.ruletype WHERE A.templateid = B.templateid

An alternative approach may be to use:

Update customers A--use alias set CITY_NAME=NVL (select B.city_name from tmp_cust_city b where b.customer_id=a.customer_id) . City_name)

Or

Set CITY_NAME=NVL (select B.city_name from tmp_cust_city b where b.customer_id=a.customer_id), ' unknown '

MySQL multiple table update instance three:

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 Association multiple tables for update operations

UPDATE Track INNER JOIN MV on Track.trkid=mv.mvid SET track.is_show=mv.is_show WHERE trkid<6

Equal to

UPDATE track,mv SET track.is_show=mv.is_show WHERE track.trkid=mv.mvid and Trkid<6

Example four:

UPDATE Product P INNER JOIN productprice pp on p.productid = pp.productid SET pp.price = pp.price * 0.8,p.dateupdate = CUR DATE () WHERE p.datecreated < ' 2004-01-01 '

Note : Please pay attention to the triple programming Tutorials section for more wonderful articles .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.