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