Results 1 to 4 of 4

Thread: Query in Joint

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    Unanswered: Query in Joint

    I have two tables and I want to update one table using a column present in another table with the help of JOINT query. Could someone please provide the syntax for JOINT query.

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Use MERGE statement.

    You can find examples in this forum and/or see the syntax and description in Information Center MERGE - IBM DB2 9.7 for Linux, UNIX, and Windows

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Query in Joint

    I have two tables Master and a Child. Both Master and Child table have multiple rows. I want to update multiple ROWS in Child table using one query which contains a column from Master table. In this case whether JOINT function will work, if so please provide the syntax or please suggest any other option to update the column in child table.

  4. #4
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    I guessed that all Child table rows have a corresponding row in Master table.
    In other words, Child table has logically foreign key constraint to Master table
    (Wheather you defined explicitly FOREIGN KEY in your table or not.)

    Then try
    Code:
    UPDATE Child_table c
       SET (col_a , col_b , ...)
         = (SELECT col_x , col_y , ...
             FROM Master_table m
             WHERE <matching conditions>
           )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •