Same Table Record Update (use the value of one record in the same table to update the values of other records in this table)

Source: Internet
Author: User

This is the version of different tables.

Update table_1 set
Price = B. Price
From table_1
Inner join table_2 B
On table_1. [type] In (1)
Where B. [type] = 1 and B. Price = 44

 

The same table is

Declare @ caseid int
Declare @ caseparentid int
Set @ caseid = 160
Set @ caseparentid = 122
 
Update cos_passengerinfo set
[Name] = B. Name
, [Sexcode] = B. sexcode
, [Identityno] = B. identityno
, [Age] = B. Age
, [Room] = B. Room
, [FLOOR] = B. [Floor]
, [Block] = B. Block
, [Building] = B. Building
, [Estate] = B. Estate
, [Street] = B. Street
, [District] = B. District
, [District2code] = B. district2code
, [Country] = B. Country
, [Telno] = B. telno
, [Emailaddress] = B. emailaddress
, [Referredby] = B. referredby
, [Lastupduser] = B. lastupduser
, [Lastupdtime] = B. lastupdtime
From cos_passengerinfo
Inner join cos_passengerinfo B
-- Destination
On cos_passengerinfo.caseid in
(
Select caseid from cos_case
Where caseparentid = @ caseparentid
And caseid <> @ caseid
And opiniontype = 2
)
--- Source
Where B. caseid = @ caseid

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.