MySQL multiple table associated update update SQL statement

Source: Internet
Author: User
Tags join

Perform updates on a single table nothing more to say than to update table_name set col1 = Xx,col2 = yy where col = zz, which is mainly the setting of the Where condition. Sometimes updating a table may involve more than one datasheet, for example:

The code is as follows Copy Code

Update Table_1 Set score = score + 5 where UID in (select UID from table_2 where sid = 10);

In fact, update can also be used to the left join, inner join to the association, may be more efficient, the above SQL to replace the join method as follows:

Update table_1 t1 INNER join table_2 t2 on t1.uid = T2.uid Set score = score + 5 where T2.sid = 10;


MySQL Association Multiple tables for update operations

  code is as follows copy code

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


equals /p>


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

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.