MySQL uses one column of a table to update a column of another table

Source: Internet
Author: User

Demand:

The boss gave an Excel data, is a template I provide, including ID, now equivalent to import this new column of data to a table in the database.

Method One: Use Navicat, copy a column in Excel, and then paste it into a column in the Navicat

Method two: Using SQL method: First build a temporary table, import the data, there are IDs and desc two columns, and then execute the following statement

UPDATE Gy_doctor A, gy_tmp b SET a.dr_desc = b. ' desc '
WHERE a.dr_id = b.id;

With table T1:

ID Name
1 null
2 NULL
3 null

Table T2:

ID Name
1 AA
2 BB
3 cc

Now you want to assign the name column of T2 to the name column of T1, with the ID as the corresponding row:

Update T1,t2
Set T1.name=t2.name
where t1.id=t2.id

Results after execution: Table T1:
ID Name
1 AA
2 BB
3 cc

MySQL uses one column of a table to update another column of this table:

With table T1:

ID Name
1 null
2 NULL
3 null

Now copy the value of the ID column of the T1 table to the T1 name columns:

Update T1
Set Name=id

Results after execution: Table T1:
ID Name
1 1
2 2
3 3

MySQL uses one column of a table to update a column of another table

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.