Requirements: Copy one of the field contents of a table to a field in another table.
Implementing SQL Statement 1:
Copy Code code 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);
Implementing SQL Statement 2:
Copy Code code as follows:
Update B Set extra = A.extra from join B on (a.id = b.id);
Implementing SQL Statement 3:
Copy Code code as follows:
Update B Set b.sms = (select A.sms from a WHERE a.id = b.ID)
You need to determine that the IDs in the two tables are primary keys or unique
Implementing SQL Statement 4:
Copy Code code 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);
Implementing SQL Statement 5:
To copy one table field data to another, you can write this:
Implementing SQL Statement 5:
Copy Code code as follows:
UPDATE tb_1 INNER JOIN tb_2 on tb_1.tid = Tb_2.tid
SET tb_1.tcontent = tb_2.tcontent
Attached: copy of same table
Requirements: Copy the contents of one field from the same table to another field
Example 1:
I want to copy the contents of a field from the article table to the B field in the article table. The SQL statement is:
Copy Code code as follows:
Example 2:
Sometimes we need to copy a whole column of data from one field to another in a new field, which is simple, SQL can write:
Copy Code code as follows:
UPDATE tb_1 SET content_target = Content_source;
The general wording is as follows:
Copy Code code as follows:
Update {your_table} set {Source_field} = {Object_field} WHERE cause