SQL assigns a column in a table to a column in another table.

Source: Internet
Author: User

SQL assigns a column in a table to a column in another table.

In the same database, I want to copy a column in a table (table 1, to another table (table 2. To keep other columns in Table 2, replace the values of one column in table 2 with the one column in table 1.

Update Table 2 set (column name to be inserted) = select table 1. A column from table 1 left jion table 2 on table 1 and table 2 association where .....

or

Update Table 1 set table 1. column = table 2. column from table 2 where Table 2.id= table 1.id
or
Update _ A set column = _ B. from table 1 _ A join Table 2 _ B on _. id = _ B. ID

example:

table T1 has F1, F2, and F3 fields. Table T2 has F1, the F4 field now assigns the F4 field of T2 to the F3 field of table T1, as follows:

Update T1 set t1.f3 = t2.f4 from T2 where t1.f1 = t2.f1

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.