MySQL writing a SQL statement that copies the contents of one of a table's fields to a field in another table

Source: Internet
Author: User
Tags join one table

  Sometimes we need to copy a whole column of data from one field to another, or we need to copy the value of one of the fields from one table to a field in another table, this article lists some of the SQL statements, and the friends you need can refer to the following

  Requirements: Copy one of the field contents of a table to a field in another table.   Implementation of SQL statement 1:     Code as follows: UPDATE File_manager_folder F1 left OUTER JOIN file_manager_folder f2    &NB Sp On f1.name = f2.name and F2.parentid = the SET F1.parentid = 54  WHERE f2.name is NULL and f1.id in (1,2,3);   Implementation of SQL Statement 2:       Code as follows: Update B set extra = A.extra from A join B on (a.id = b.id);   Implementing SQL Statement 3:     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 two tables are primary keys or only   Implementing 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 W Here a.id = b.id);   Implementation of SQL statement 5: Copy a table field data to another list of fields, you can write: 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.tco Ntent = tb_2.tcontent     Attach: Same table replication   requirements: Copy the contents of one field of 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:       Code as follows: Update article set b=a;   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: &nbsp Code as follows: UPDATE tb_1 SET content_target = Content_source; The following is roughly written: The code is as follows: Update {your_table} set {Source_field} = {Object_field} WHERE cause
Related Article

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.