[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Add contents of one table's column to another table

Posted on 2007-03-26
4
Medium Priority
?
289 Views
Last Modified: 2010-03-20
Sorry, I'm a real newbie to SQL. I have two tables with the same columns and would like to do the following:

Add the contents of Table2.ColumnX to Table1.ColumnX where Table1.pkID = Table2.pkID (all the rows are the same in both tables except for the values of ColumnX)

Thanks in advance for any help!
0
Comment
Question by:siono3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 18796591
Try this:

SELECT Table2.ColumnX + Table1.ColumnX  as YourSum
FROM  Table1 Inner Join Table2 ON Table1.pkID = Table2.pkID
0
 
LVL 61

Expert Comment

by:mbizup
ID: 18796599
If you actually need to update Table1's data, not just a select query, make a backup and try this:

Update Table1 Inner Join Table2 ON Table1.pkID = Table2.pkID
SET  Table2.ColumnX  = Table2.ColumnX + Table1.ColumnX  
0
 
LVL 61

Accepted Solution

by:
mbizup earned 750 total points
ID: 18796611
Correction... The update query I posted before will update table2's data.  This will update table1:

Update Table1 Inner Join Table2 ON Table1.pkID = Table2.pkID
SET  Table1.ColumnX  = Table2.ColumnX + Table1.ColumnX  
0
 

Author Comment

by:siono3
ID: 18799320
Thanks mbizup,

That almost worked. For some reason I had to tweak it a little bit and ended up with the following:
UPDATE    Table1
SET              Table1.ColumnX = Table2.ColumnX
FROM         Table1 INNER JOIN
                      Table2 ON Table1.pkID = Table2.pkID

but you set me on the right track...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question