MySQL different library table field data replication

Source: Internet
Author: User

Requirement: Copy one table field content to a field in another table.

Implementing SQL Statement 1:

UPDATE file_manager_folder f1left OUTER JOIN file_manager_folder f2 on     f1.name = f2.name and F2.parentid = 54SET F1.PA Rentid = F2.name is NULL and f1.id in (All-in-all);

  

Implementing SQL Statement 2:

Update B Set extra = A.extra from A join B on (a.id = b.id);

I tried, like, an error.

  

Implementing SQL Statement 3:

Update B Set b.sms = (select A.sms from a WHERE a.id = b.ID)

  

You need to determine whether the IDs in the two tables are primary keys or unique

Implementing SQL Statement 4:

UPDATE A SET a.sms = (select b.sms from b where a.id = b.ID) where EXISTS (select 1 from b where a.id = b.ID);

  

Implementing SQL Statement 5:
To copy one table field data to another, you can write:
Implementing SQL Statement 5:

UPDATE tb_1 INNER JOIN tb_2 on tb_1.tid = Tb_2.tidset tb_1.tcontent = tb_2.tcontent

  

Attached: copy of the same table

Requirement: Copy the contents of one field in the same table into another field

Example 1:
I want to copy the contents of the A field in the article table to the B field in the article table. The SQL statement is:

Update article set b=a;

  

Example 2:
Sometimes we need to copy the entire column of data from one field to another in a new field, which is simple enough for SQL to write:

UPDATE tb_1 SET content_target = Content_source;

The approximate wording is as follows:

Update {your_table} set {Source_field} = {Object_field} WHERE cause

  

In the end, I used

UPDATE k1.tb1 kt1inner JOIN k2.tb2 kt2 on kt1.id = Kt2.idset Kt1.sex = kt2.sex

Database K1 tb1 Table synchronization database K2 TB2 table corresponding ID of sex

MySQL different library table field data replication

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.