If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Query in Joint

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-11-11, 00:58
Santhosh.R Santhosh.R is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
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.
Reply With Quote
  #2 (permalink)  
Old 07-11-11, 01:38
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
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
Reply With Quote
  #3 (permalink)  
Old 07-11-11, 02:25
Santhosh.R Santhosh.R is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 07-11-11, 02:40
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
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>
       )
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On