SQL Server Update table (data for another table is updated with data from a single table)

Source: Internet
Author: User

A) Easy to type, update efficiency:

Update table1

Set Field1=table2.field1,field2=table2.field2

From Table2 where table1.id=table2.id

b) Conventional way, this is equivalent to a left join, in the outside where is the number of updates, if not add where is all records

Update table1 Set field1=

(select top 1 field1 from table2 where table2.id=table1.id)

where table1.id in (condition)

SQL Server Update table (data for another table is updated with data from a single 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.