how to update multiple columns of a table from another table?.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amitsukte
    New Member
    • Jan 2012
    • 7

    how to update multiple columns of a table from another table?.

    Hi Everyone how should i update multiple columns of a table from another table...

    Suppose I have table A and B and having four columns each table
    A(col1,col2,col 3,col4)
    B(col1,col2,col 3,col4)



    then how should i do something like this

    update A set(col2,col4)= (select B.col2,B.col4 from B where B.col1=A.col1 and A.col3=A.col3)

    Please help..........
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Your basic query structure is correct but you should probably add a where exists
    Code:
    UPDATE A
    SET ( A.col2, A.col4 ) =
    ( SELECT B.col2, B.col4
        FROM B
       WHERE B.col1 = A.col1
    )
    WHERE EXISTS
    ( SELECT B.col2, B.col4
        FROM B
       WHERE B.col1 = A.col1
    )

    Comment

    • amitsukte
      New Member
      • Jan 2012
      • 7

      #3
      thank you very much r035198x.. its working fine..

      Comment

      Working...