DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Updating 2 tables

Hybrid View

  1. #1
    Join Date
    Sep 2000
    Posts
    384
    Hi,

    we are trying to copy 2 columns from one table to another. we were trying to use update statement to achieve this task, but we are not able to find correct syntax.

    eg:

    table 1 table2
    key1 key2
    col1 colA
    col2 colB

    We would like to update table1 with values of colA & colB from table2 where key1 is equal to key2. Any help on this query is appericated.

    thank you
    Radhakrishnan.M

  2. #2
    Join Date
    Apr 2000
    Location
    Baltimore, MD
    Posts
    759
    Try this, I think it'll work:
    update table1
    set table1.colA=table2.colA, table1.colB=table2.colB where
    key1=key2;

  3. #3
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Halo, it won't work.

    The workable statement is:

    UPDATE TABLE1 A SET (A.COL2, A.COL3) =
    (SELECT B.COL2, B.COL3 FROM TABLE2 B WHERE A.KEY1=B.KEY2);

  4. #4
    Join Date
    Sep 2000
    Posts
    384
    Thanks.

    back to basics..
    Radhakrishnan.M

Posting Permissions

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


Click Here to Expand Forum to Full Width