distal-attribute
distal-attribute
distal-attribute
distal-attribute

Adding a new Column from a separate Table...

User, date Message
Written by Ash501
2 years ago
Category: General
21 posts since Tue, 20 Mar 12
Is there an easy way to merge data from one table to another?

Need to ADD a 'whole' Column from a one Table into different one. They both have a common ID. Is there an easy way to do it with HeidiSQL?

How about a 'part' of the Column only?

Thanks for your help!
Written by ansgar
2 years ago
5023 posts since Fri, 07 Apr 06
You need to create the column name/type first in the target table. Then you can

select col from table1 into table2


While that does not update anything, but inserts, of course.
Written by ansgar
2 years ago
5023 posts since Fri, 07 Apr 06
oh, it's too early in the morning. I meant:

insert into table2 (col) select col from table1

Written by Ash501
2 years ago
21 posts since Tue, 20 Mar 12
This inserts into end of records. Need to update into current records.../or empty column...so that it would be alongside current records.

Is that what you mean by update? How is that done?
Sorry I'm new to SQL....

Thanks anse!
Written by ansgar
2 years ago
5023 posts since Fri, 07 Apr 06
In that case you will need an equal identifier column in both tables (let's call it "someuniquekey"):

UPDATE
table1 AS t1, table2 AS t2
SET t1.col=t2.col
WHERE t1.someuniquekey=t2.someuniquekey

Written by Ash501
2 years ago
21 posts since Tue, 20 Mar 12
Thanks anse!!! Just what I needed, a happy camper ={:-))
& you make it look so easy....
 

Please login to leave a reply, or register at first.