Mysql copies the content of a field in a table to the SQL statement of a field in another table.

Source: Internet
Author: User
Sometimes, we need to copy the data in the entire column of a field to another new field, or copy the value of a field in a table to a field in another table, this article lists some SQL statement writing methods. For more information, see requirements: copy the content of a field in a table to a field in another table. Implement SQL statement 1

Sometimes, we need to copy the data in the entire column of a field to another new field, or copy the value of a field in a table to a field in another table, this article lists some SQL statement writing methods. For more information, see requirements: copy the content of a field in a table to a field in another table. Implement SQL statement 1

Sometimes, we need to copy the data in the entire column of a field to another new field, or copy the value of a field in a table to a field in another table ,, this article lists some SQL statement writing methods. For more information, see

Requirement: copy the content of a field in one table to a field in another table.

Implement SQL statement 1:

The Code is as follows:

UPDATE file_manager_folder f1

Left outer join file_manager_folder f2

ON f1.name = f2.name AND f2.parentId = 54

SET f1.parentId = 54

WHERE f2.name is null and f1.id IN (1, 2, 3 );

Implement SQL statement 2:

The Code is as follows: update B set extra = A. extra from A join B on (A. id = B. id );

Implement SQL statement 3:

The Code is as follows: update B set B. sms = (select a. sms from a where a. id = B. id)

Make sure that the IDs of the two tables are both primary keys or unique.

Implement SQL statement 4:

The Code is as follows:

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 );

Implement SQL statement 5:

Copy a table field data to another table field, which can be written as follows:

Implement SQL statement 5:

The Code is as follows:

UPDATE tb_1 inner join tb_2 ON tb_1.tid = tb_2.tid

SET tb_1.tcontent = tb_2.tcontent

Appendix: Same table replication

Requirement: copy the content in one field of the same table to another field.

Example 1:

I want to copy the content of field A in the article table to the SQL statement in field B in the article table:

The Code is as follows: update article set B =;

Example 2:

Sometimes, we need to copy the data in the entire column of a field to another new field, which is very simple. The SQL statement can be written as follows:

The Code is as follows: UPDATE tb_1 SET content_target = content_source;

The syntax is as follows:

The Code is as follows: Update {your_table} set {source_field }={ object_field} WHERE cause

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.