By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,842 Members | 2,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,842 IT Pros & Developers. It's quick & easy.

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

P: 7
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,col3,col4)
B(col1,col2,col3,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..........
Mar 9 '12 #1

✓ answered by r035198x

Your basic query structure is correct but you should probably add a where exists
Expand|Select|Wrap|Line Numbers
  1. UPDATE A
  2. SET ( A.col2, A.col4 ) =
  3. ( SELECT B.col2, B.col4
  4.     FROM B
  5.    WHERE B.col1 = A.col1
  6. )
  7. WHERE EXISTS
  8. ( SELECT B.col2, B.col4
  9.     FROM B
  10.    WHERE B.col1 = A.col1
  11. )
  12.  

Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
Your basic query structure is correct but you should probably add a where exists
Expand|Select|Wrap|Line Numbers
  1. UPDATE A
  2. SET ( A.col2, A.col4 ) =
  3. ( SELECT B.col2, B.col4
  4.     FROM B
  5.    WHERE B.col1 = A.col1
  6. )
  7. WHERE EXISTS
  8. ( SELECT B.col2, B.col4
  9.     FROM B
  10.    WHERE B.col1 = A.col1
  11. )
  12.  
Mar 9 '12 #2

P: 7
thank you very much r035198x.. its working fine..
Mar 9 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.