473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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,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.  

2 41938
r035198x
13,262 8TB
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
thank you very much r035198x.. its working fine..
Mar 9 '12 #3

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

Similar topics

5
by: Mike | last post by:
Here is my situation; I have two tables in a MS-SQL DB. One table with dollar amounts and service codes. I have a second table that I want to move some information into from the first table. The...
4
by: Dave [Hawk-Systems] | last post by:
have a data table that records entries by date(unix timestamp) and customer number. each custnum will have several entries showing a running ledger type snapshot. we have the need to get the most...
1
by: Tony Johnson | last post by:
I want to update a particular field in a form for only a certain set of records. The certain set of records is named Financed. I need to update those Financed records with a financed number that...
1
by: N. Graves | last post by:
I have a table(Useraccess that has several different columns of data (userid, password, num_of_access etc) I get a different table of user info data every couple of days. The NewTable has only the...
6
by: Dale | last post by:
I'm not sure I'm even thinking about this the right way, but here goes: I have a table of users. Each one of these users may be associated with none, one, or many records in another table I call...
2
by: BF | last post by:
Hi, I have some tables where I import data in, lots of field have gotten a NULL value which the application can not handle. Now can I replace each NULL value with '' in a columns with: update...
1
by: jlrolin | last post by:
I'm trying to update a new field in a table from a COUNT(*) of Registration IDs grouped by Course IDs. COUNT: Course_ID 11 1234 12 2323 19 8932 ...
1
by: jmarr02s | last post by:
I am trying to "Copy all columns from another table" here is the SQL code I am using in MS Access: CREATE TABLE suppliers AS (SELECT * FROM companies WHERE id 1000); I think I got it to...
3
by: zuchowra | last post by:
Hello everyone. Im running Access 2007. The form i created logs a persons ID badge number and personal information however, i want to make a section that lists their skills. So I will add a button...
0
by: anureddy | last post by:
help me how to add datagridview columns to another table,using windowsapplications. and set the displaymember and value member datagridviewcomboboxcolumn. i used this below code but that not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.