Update all values of a column in a table to be equal to the values of a column in another table.

Source: Internet
Author: User

The database uses db2, which has two tables: Check table (STUDY_TBL) and filter table (SELECTION_TBL)

========================================

The description of STUDY_TBL is roughly as follows:

STUDY_LID integer primary key,

STUDY_DATE DATE

......

The definition of SELECTION_TBL is roughly as follows:

SELECTION_LID integer primary key,

STUDY_LID INTEGER,

STUDY_DATE

......

============================================

STUDY_LID is not unique in SELECTION_TBL. Now we want to update all STUDY_DATE in SELECTION_TBL to be the same as STUDY_DATE in STUDY_TBL (that is, in the two tables, STUDY _ and LID are the same, STUDY_DATE in SELECTION_TBL must be the same as STUDY_DATE in STUDY_TBL ).

The SQL statement is as follows:


Update pacs. SELECTION_TBL SEL
SET STUDY_DATE = (select st. STUDY_DATE
From pacs. STUDY_TBL ST
Where st. STUDY_LID = SEL. STUDY_LID)
WHERE EXISTS
(SELECT 1 from pacs. STUDY_TBL ST1 WHERE ST1.STUDY _ LID = SEL. STUDY_LID)


PACS is the mode name. We will discuss the usage of exists in detail in future articles ....

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.