Use SQL to update the data of the current table with reference to another table

Source: Internet
Author: User
Use SQL to update the data of the current table with reference to another table
Assume that the A2 and A3 fields in Table A need to be updated. The condition is that A1 is equal to B1 in Table B:

Create Table qgpl/A (A1 char (1), A2 char (1), A3 char (1 ));
Create Table qgpl/B (b1 char (1), B2 char (1), B3 char (1 ));
Insert into qbpl/A values ('1', 'A', 'B ');
Insert into qbpl/A values ('2', 'C', 'D ');
Insert into qbpl/B values ('1', '0', '1 ');

Update qgpl/A as Table1
Set (A2, A3) =
(Select B2, B3 from qgpl/B as Table2 -- => the search condition must be unique; otherwise, the set fails.
Where table2.b1 = table1.a1 ))

Where table1.a1 not in --------------- => only modify the records of Table A with the same data in table B.
(Select B1 from qgpl/B );

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.